docs: Add CLAUDE.md with codebase guidance

Create comprehensive documentation for future Claude Code instances working in this repository, including:
- Development commands for testing, building, and code quality
- Core architecture overview of the SQL query builder system
- Directory structure and component explanations
- Testing patterns and conventions
- Key dependencies and their purposes

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-27 15:47:28 +08:00
co-authored by Claude
parent 764eccfafd
commit 304d553b3c
113 changed files with 914 additions and 432 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ package exp_test
import (
"testing"
"git.fsdpf.net/go/db/v2/exp"
"git.fsdpf.net/go/db/exp"
"github.com/stretchr/testify/suite"
)
+1 -1
View File
@@ -3,7 +3,7 @@ package exp_test
import (
"testing"
"git.fsdpf.net/go/db/v2/exp"
"git.fsdpf.net/go/db/exp"
"github.com/stretchr/testify/suite"
)
+1 -1
View File
@@ -3,7 +3,7 @@ package exp_test
import (
"testing"
"git.fsdpf.net/go/db/v2/exp"
"git.fsdpf.net/go/db/exp"
"github.com/stretchr/testify/suite"
)
+1 -1
View File
@@ -3,7 +3,7 @@ package exp_test
import (
"testing"
"git.fsdpf.net/go/db/v2/exp"
"git.fsdpf.net/go/db/exp"
"github.com/stretchr/testify/suite"
)
+9 -2
View File
@@ -4,7 +4,7 @@ import (
"fmt"
"reflect"
"git.fsdpf.net/go/db/v2/internal/util"
"git.fsdpf.net/go/db/internal/util"
)
type columnList struct {
@@ -23,7 +23,8 @@ func NewColumnListExpression(vals ...interface{}) ColumnListExpression {
case Expression:
cols = append(cols, t)
default:
_, valKind := util.GetTypeInfo(val, reflect.Indirect(reflect.ValueOf(val)))
refVal := reflect.Indirect(reflect.ValueOf(val))
_, valKind := util.GetTypeInfo(val, refVal)
if valKind == reflect.Struct {
cm, err := util.GetColumnMap(val)
@@ -39,6 +40,12 @@ func NewColumnListExpression(vals ...interface{}) ColumnListExpression {
}
cols = append(cols, sc)
}
} else if refVal.Kind() == reflect.Slice {
items := make([]any, refVal.Len())
for i := 0; i < refVal.Len(); i++ {
items[i] = refVal.Index(i).Interface()
}
return NewColumnListExpression(items...)
} else {
panic(fmt.Sprintf("Cannot create expression from %+v", val))
}
+5 -5
View File
@@ -8,8 +8,8 @@ type (
CommonTables() []CommonTableExpression
CommonTablesAppend(cte CommonTableExpression) DeleteClauses
From() IdentifierExpression
SetFrom(table IdentifierExpression) DeleteClauses
From() ColumnListExpression
SetFrom(table ColumnListExpression) DeleteClauses
Where() ExpressionList
ClearWhere() DeleteClauses
@@ -33,7 +33,7 @@ type (
}
deleteClauses struct {
commonTables []CommonTableExpression
from IdentifierExpression
from ColumnListExpression
where ExpressionList
order ColumnListExpression
limit interface{}
@@ -71,11 +71,11 @@ func (dc *deleteClauses) CommonTablesAppend(cte CommonTableExpression) DeleteCla
return ret
}
func (dc *deleteClauses) From() IdentifierExpression {
func (dc *deleteClauses) From() ColumnListExpression {
return dc.from
}
func (dc *deleteClauses) SetFrom(table IdentifierExpression) DeleteClauses {
func (dc *deleteClauses) SetFrom(table ColumnListExpression) DeleteClauses {
ret := dc.clone()
ret.from = table
return ret
+4 -4
View File
@@ -3,7 +3,7 @@ package exp_test
import (
"testing"
"git.fsdpf.net/go/db/v2/exp"
"git.fsdpf.net/go/db/exp"
"github.com/stretchr/testify/suite"
)
@@ -17,7 +17,7 @@ func TestDeleteClausesSuite(t *testing.T) {
func (dcs *deleteClausesSuite) TestHasFrom() {
c := exp.NewDeleteClauses()
c2 := c.SetFrom(exp.NewIdentifierExpression("", "test", ""))
c2 := c.SetFrom(exp.NewColumnListExpression("test"))
dcs.False(c.HasFrom())
@@ -26,7 +26,7 @@ func (dcs *deleteClausesSuite) TestHasFrom() {
func (dcs *deleteClausesSuite) TestFrom() {
c := exp.NewDeleteClauses()
ti := exp.NewIdentifierExpression("", "a", "")
ti := exp.NewColumnListExpression("a")
c2 := c.SetFrom(ti)
dcs.Nil(c.From())
@@ -36,7 +36,7 @@ func (dcs *deleteClausesSuite) TestFrom() {
func (dcs *deleteClausesSuite) TestSetFrom() {
c := exp.NewDeleteClauses()
ti := exp.NewIdentifierExpression("", "a", "")
ti := exp.NewColumnListExpression("a")
c2 := c.SetFrom(ti)
dcs.Nil(c.From())
+1 -1
View File
@@ -3,7 +3,7 @@ package exp
import (
"fmt"
"git.fsdpf.net/go/db/v2/internal/sb"
"git.fsdpf.net/go/db/internal/sb"
)
// Behaviors
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"sort"
"strings"
"git.fsdpf.net/go/db/v2/internal/errors"
"git.fsdpf.net/go/db/internal/errors"
)
type (
+1 -1
View File
@@ -3,7 +3,7 @@ package exp_test
import (
"testing"
"git.fsdpf.net/go/db/v2/exp"
"git.fsdpf.net/go/db/exp"
"github.com/stretchr/testify/suite"
)
+1 -1
View File
@@ -3,7 +3,7 @@ package exp_test
import (
"testing"
"git.fsdpf.net/go/db/v2/exp"
"git.fsdpf.net/go/db/exp"
"github.com/stretchr/testify/suite"
)
+1 -1
View File
@@ -3,7 +3,7 @@ package exp_test
import (
"testing"
"git.fsdpf.net/go/db/v2/exp"
"git.fsdpf.net/go/db/exp"
"github.com/stretchr/testify/suite"
)
+2 -2
View File
@@ -4,8 +4,8 @@ import (
"reflect"
"sort"
"git.fsdpf.net/go/db/v2/internal/errors"
"git.fsdpf.net/go/db/v2/internal/util"
"git.fsdpf.net/go/db/internal/errors"
"git.fsdpf.net/go/db/internal/util"
)
type (
+1 -1
View File
@@ -3,7 +3,7 @@ package exp_test
import (
"testing"
"git.fsdpf.net/go/db/v2/exp"
"git.fsdpf.net/go/db/exp"
"github.com/stretchr/testify/suite"
)
+1 -1
View File
@@ -3,7 +3,7 @@ package exp_test
import (
"testing"
"git.fsdpf.net/go/db/v2/exp"
"git.fsdpf.net/go/db/exp"
"github.com/stretchr/testify/suite"
)
+1 -1
View File
@@ -3,7 +3,7 @@ package exp_test
import (
"testing"
"git.fsdpf.net/go/db/v2/exp"
"git.fsdpf.net/go/db/exp"
"github.com/stretchr/testify/suite"
)
+1 -1
View File
@@ -3,7 +3,7 @@ package exp_test
import (
"testing"
"git.fsdpf.net/go/db/v2/exp"
"git.fsdpf.net/go/db/exp"
"github.com/stretchr/testify/suite"
)
+1 -1
View File
@@ -4,7 +4,7 @@ import (
"reflect"
"sort"
"git.fsdpf.net/go/db/v2/internal/util"
"git.fsdpf.net/go/db/internal/util"
)
// Alternative to writing map[string]interface{}. Can be used for Inserts, Updates or Deletes
+14
View File
@@ -22,6 +22,7 @@ type (
Joins() JoinExpressions
JoinsAppend(jc JoinExpression) SelectClauses
JoinsPrepend(jc JoinExpression) SelectClauses
Where() ExpressionList
ClearWhere() SelectClauses
@@ -41,6 +42,7 @@ type (
GroupBy() ColumnListExpression
SetGroupBy(cl ColumnListExpression) SelectClauses
GroupByAppend(cl ColumnListExpression) SelectClauses
ClearGroupBy() SelectClauses
Limit() interface{}
HasLimit() bool
@@ -197,6 +199,12 @@ func (c *selectClauses) JoinsAppend(jc JoinExpression) SelectClauses {
return ret
}
func (c *selectClauses) JoinsPrepend(jc JoinExpression) SelectClauses {
ret := c.clone()
ret.joins = append(JoinExpressions{jc}, ret.joins...)
return ret
}
func (c *selectClauses) Where() ExpressionList {
return c.where
}
@@ -310,6 +318,12 @@ func (c *selectClauses) SetGroupBy(cl ColumnListExpression) SelectClauses {
return ret
}
func (c *selectClauses) ClearGroupBy() SelectClauses {
ret := c.clone()
ret.groupBy = nil
return ret
}
func (c *selectClauses) Limit() interface{} {
return c.limit
}
+1 -1
View File
@@ -3,7 +3,7 @@ package exp_test
import (
"testing"
"git.fsdpf.net/go/db/v2/exp"
"git.fsdpf.net/go/db/exp"
"github.com/stretchr/testify/suite"
)
+1 -1
View File
@@ -3,7 +3,7 @@ package exp_test
import (
"testing"
"git.fsdpf.net/go/db/v2/exp"
"git.fsdpf.net/go/db/exp"
"github.com/stretchr/testify/suite"
)
+2 -2
View File
@@ -4,8 +4,8 @@ import (
"reflect"
"sort"
"git.fsdpf.net/go/db/v2/internal/errors"
"git.fsdpf.net/go/db/v2/internal/util"
"git.fsdpf.net/go/db/internal/errors"
"git.fsdpf.net/go/db/internal/util"
)
type (
+1 -1
View File
@@ -3,7 +3,7 @@ package exp_test
import (
"testing"
"git.fsdpf.net/go/db/v2/exp"
"git.fsdpf.net/go/db/exp"
"github.com/stretchr/testify/suite"
)
+1 -1
View File
@@ -3,7 +3,7 @@ package exp_test
import (
"testing"
"git.fsdpf.net/go/db/v2/exp"
"git.fsdpf.net/go/db/exp"
"github.com/stretchr/testify/suite"
)
+1 -1
View File
@@ -3,7 +3,7 @@ package exp_test
import (
"testing"
"git.fsdpf.net/go/db/v2/exp"
"git.fsdpf.net/go/db/exp"
"github.com/stretchr/testify/suite"
)
+1 -1
View File
@@ -3,7 +3,7 @@ package exp_test
import (
"testing"
"git.fsdpf.net/go/db/v2/exp"
"git.fsdpf.net/go/db/exp"
"github.com/stretchr/testify/suite"
)