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:
+42
-7
@@ -4,10 +4,10 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.fsdpf.net/go/db/v2/exec"
|
||||
"git.fsdpf.net/go/db/v2/exp"
|
||||
"git.fsdpf.net/go/db/v2/internal/errors"
|
||||
"git.fsdpf.net/go/db/v2/internal/sb"
|
||||
"git.fsdpf.net/go/db/exec"
|
||||
"git.fsdpf.net/go/db/exp"
|
||||
"git.fsdpf.net/go/db/internal/errors"
|
||||
"git.fsdpf.net/go/db/internal/sb"
|
||||
)
|
||||
|
||||
// Dataset for creating and/or executing SELECT SQL statements.
|
||||
@@ -17,6 +17,7 @@ type SelectDataset struct {
|
||||
isPrepared prepared
|
||||
queryFactory exec.QueryFactory
|
||||
err error
|
||||
hooks exec.Hooks
|
||||
}
|
||||
|
||||
var ErrQueryFactoryNotFoundError = errors.New(
|
||||
@@ -94,6 +95,7 @@ func (sd *SelectDataset) copy(clauses exp.SelectClauses) *SelectDataset {
|
||||
isPrepared: sd.isPrepared,
|
||||
queryFactory: sd.queryFactory,
|
||||
err: sd.err,
|
||||
hooks: sd.hooks,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,6 +123,7 @@ func (sd *SelectDataset) Update() *UpdateDataset {
|
||||
}
|
||||
}
|
||||
u.clauses = c
|
||||
u.hooks = sd.hooks
|
||||
return u
|
||||
}
|
||||
|
||||
@@ -130,13 +133,18 @@ func (sd *SelectDataset) Insert() *InsertDataset {
|
||||
i := newInsertDataset(sd.dialect.Dialect(), sd.queryFactory).
|
||||
Prepared(sd.isPrepared.Bool())
|
||||
if sd.clauses.HasSources() {
|
||||
i = i.Into(sd.GetClauses().From().Columns()[0])
|
||||
if from, ok := sd.GetClauses().From().Columns()[0].(exp.AliasedExpression); ok {
|
||||
i = i.Into(from.Aliased())
|
||||
} else {
|
||||
i = i.Into(from)
|
||||
}
|
||||
}
|
||||
c := i.clauses
|
||||
for _, ce := range sd.clauses.CommonTables() {
|
||||
c = c.CommonTablesAppend(ce)
|
||||
}
|
||||
i.clauses = c
|
||||
i.hooks = sd.hooks
|
||||
return i
|
||||
}
|
||||
|
||||
@@ -164,6 +172,7 @@ func (sd *SelectDataset) Delete() *DeleteDataset {
|
||||
}
|
||||
}
|
||||
d.clauses = c
|
||||
d.hooks = sd.hooks
|
||||
return d
|
||||
}
|
||||
|
||||
@@ -353,6 +362,11 @@ func (sd *SelectDataset) joinTable(join exp.JoinExpression) *SelectDataset {
|
||||
return sd.copy(sd.clauses.JoinsAppend(join))
|
||||
}
|
||||
|
||||
// Joins this Datasets table with another, prepend
|
||||
func (sd *SelectDataset) JoinPrepend(table exp.Expression, condition exp.JoinCondition, joinType exp.JoinType) *SelectDataset {
|
||||
return sd.copy(sd.clauses.JoinsPrepend(exp.NewConditionedJoinExpression(joinType, table, condition)))
|
||||
}
|
||||
|
||||
// Adds a WHERE clause. See examples.
|
||||
func (sd *SelectDataset) Where(expressions ...exp.Expression) *SelectDataset {
|
||||
return sd.copy(sd.clauses.WhereAppend(expressions...))
|
||||
@@ -387,6 +401,11 @@ func (sd *SelectDataset) withLock(strength exp.LockStrength, option exp.WaitOpti
|
||||
return sd.copy(sd.clauses.SetLock(exp.NewLock(strength, option, of...)))
|
||||
}
|
||||
|
||||
// Removes the Group BY clause. See examples.
|
||||
func (sd *SelectDataset) ClearGroupBy() *SelectDataset {
|
||||
return sd.copy(sd.clauses.ClearGroupBy())
|
||||
}
|
||||
|
||||
// Adds a GROUP BY clause. See examples.
|
||||
func (sd *SelectDataset) GroupBy(groupBy ...interface{}) *SelectDataset {
|
||||
return sd.copy(sd.clauses.SetGroupBy(exp.NewColumnListExpression(groupBy...)))
|
||||
@@ -551,8 +570,24 @@ func (sd *SelectDataset) ToSQL() (sql string, params []interface{}, err error) {
|
||||
// db.From("test").Select("col").Executor()
|
||||
//
|
||||
// See Dataset#ToUpdateSQL for arguments
|
||||
func (sd *SelectDataset) Executor() exec.QueryExecutor {
|
||||
return sd.queryFactory.FromSQLBuilder(sd.selectSQLBuilder())
|
||||
func (sd *SelectDataset) Executor() (executor exec.QueryExecutor) {
|
||||
if sd.hooks != nil {
|
||||
sd.SetError(sd.hooks.Before(sd))
|
||||
}
|
||||
executor = sd.queryFactory.FromSQLBuilder(sd.selectSQLBuilder())
|
||||
if sd.hooks != nil {
|
||||
executor.Hook(func(result interface{}) error {
|
||||
return sd.hooks.After(sd, result)
|
||||
})
|
||||
}
|
||||
return executor
|
||||
}
|
||||
|
||||
func (sd *SelectDataset) WithHook(hooks exec.Hooks) *SelectDataset {
|
||||
if sd.hooks == nil {
|
||||
sd.hooks = hooks
|
||||
}
|
||||
return sd
|
||||
}
|
||||
|
||||
// Appends this Dataset's SELECT statement to the SQLBuilder
|
||||
|
||||
Reference in New Issue
Block a user