add sqimple crud methods

This commit is contained in:
2026-09-01 01:29:27 +01:00
parent efa486fea8
commit 0d73340982
3 changed files with 38 additions and 0 deletions
+1
View File
@@ -4,6 +4,7 @@ go 1.25.7
require ( require (
code.aneur.in/go/record v0.0.0-20260704022026-db3f74ccdeb4 code.aneur.in/go/record v0.0.0-20260704022026-db3f74ccdeb4
code.aneur.in/go/sqimple v0.0.0-20260710160754-2a04163d6eff
code.aneur.in/go/version v0.0.0-20260706210436-9f229dde97c9 code.aneur.in/go/version v0.0.0-20260706210436-9f229dde97c9
modernc.org/sqlite v1.57.0 modernc.org/sqlite v1.57.0
) )
+8
View File
@@ -1,7 +1,13 @@
code.aneur.in/go/record v0.0.0-20260704022026-db3f74ccdeb4 h1:cE8tCjhHePkEMBEQbkuTy/NQ5DlAoDwRPQERqcZK5DM= code.aneur.in/go/record v0.0.0-20260704022026-db3f74ccdeb4 h1:cE8tCjhHePkEMBEQbkuTy/NQ5DlAoDwRPQERqcZK5DM=
code.aneur.in/go/record v0.0.0-20260704022026-db3f74ccdeb4/go.mod h1:nIqf1d1YWOPSVrbBFJY2ZBEMMFSfQCgXL7nFVXOzVqo= code.aneur.in/go/record v0.0.0-20260704022026-db3f74ccdeb4/go.mod h1:nIqf1d1YWOPSVrbBFJY2ZBEMMFSfQCgXL7nFVXOzVqo=
code.aneur.in/go/sqimple v0.0.0-20260710160754-2a04163d6eff h1:DAZPseBNreEYH4XQG087NfQ+PpHIlpYVThRXKmRkupc=
code.aneur.in/go/sqimple v0.0.0-20260710160754-2a04163d6eff/go.mod h1:WT64312MyLtL4EiJWRyBFh+Tl//ls2+B+YsFV+BkPJ0=
code.aneur.in/go/version v0.0.0-20260706210436-9f229dde97c9 h1:OquK0VYWHUts7u/23A6IiZ0PkznhIihj9U0DBSXfeM0= code.aneur.in/go/version v0.0.0-20260706210436-9f229dde97c9 h1:OquK0VYWHUts7u/23A6IiZ0PkznhIihj9U0DBSXfeM0=
code.aneur.in/go/version v0.0.0-20260706210436-9f229dde97c9/go.mod h1:G26bUe3Jroua1UDRzJO12ssn6OPcTsizffKJ+5/FK7U= code.aneur.in/go/version v0.0.0-20260706210436-9f229dde97c9/go.mod h1:G26bUe3Jroua1UDRzJO12ssn6OPcTsizffKJ+5/FK7U=
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
@@ -12,6 +18,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/mattn/go-isatty v0.0.24 h1:tGZZoVgT/KiqK1c8ocVLeDS8BSWMRd47J3Lbz7vsReI= github.com/mattn/go-isatty v0.0.24 h1:tGZZoVgT/KiqK1c8ocVLeDS8BSWMRd47J3Lbz7vsReI=
github.com/mattn/go-isatty v0.0.24/go.mod h1:nMCL3Zebbrt45jsMDgnfIwz6ydEQApk5oEI3HqDio6A= github.com/mattn/go-isatty v0.0.24/go.mod h1:nMCL3Zebbrt45jsMDgnfIwz6ydEQApk5oEI3HqDio6A=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w= github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
+29
View File
@@ -5,6 +5,7 @@ import (
"database/sql" "database/sql"
"code.aneur.in/go/record" "code.aneur.in/go/record"
"code.aneur.in/go/sqimple"
"code.aneur.in/go/version" "code.aneur.in/go/version"
) )
@@ -15,10 +16,18 @@ type Scaffold struct {
apps map[string]version.Migration apps map[string]version.Migration
} }
func (s *Scaffold) Delete(from string) *sqimple.DeleteStatement {
return sqimple.Delete(from).ExecFunc(s.sqimpleExec)
}
func (s *Scaffold) Exec(query string, args ...any) (sql.Result, error) { func (s *Scaffold) Exec(query string, args ...any) (sql.Result, error) {
return s.conn.ExecContext(s.ctx, query, args...) return s.conn.ExecContext(s.ctx, query, args...)
} }
func (s *Scaffold) Insert(into string) *sqimple.InsertStatement {
return sqimple.Insert(into).ExecFunc(s.sqimpleExec)
}
func (s *Scaffold) Query(query string, args ...any) ([]record.Record, error) { func (s *Scaffold) Query(query string, args ...any) ([]record.Record, error) {
rows, err := s.conn.QueryContext(s.ctx, query, args...) rows, err := s.conn.QueryContext(s.ctx, query, args...)
if err != nil { if err != nil {
@@ -37,6 +46,26 @@ func (s *Scaffold) QueryOne(query string, args ...any) (record.Record, error) {
return ScanOneRecord(rows) return ScanOneRecord(rows)
} }
func (s *Scaffold) Select(from string) *sqimple.SelectQuery {
return sqimple.Select(from).QueryFunc(s.sqimpleQuery).QueryRowFunc(s.sqimpleQueryRow)
}
func (s *Scaffold) Update(table string) *sqimple.UpdateStatement {
return sqimple.Update(table).ExecFunc(s.sqimpleExec)
}
func (s *Scaffold) sqimpleExec(query sqimple.Query) (sql.Result, error) {
return s.Exec(query.String(), query.Args()...)
}
func (s *Scaffold) sqimpleQuery(query sqimple.Query) (*sql.Rows, error) {
return s.conn.QueryContext(s.ctx, query.String(), query.Args()...)
}
func (s *Scaffold) sqimpleQueryRow(query sqimple.Query) *sql.Row {
return s.conn.QueryRowContext(s.ctx, query.String(), query.Args()...)
}
func (s *Scaffold) WithApp(name string, migration version.Migration) *Scaffold { func (s *Scaffold) WithApp(name string, migration version.Migration) *Scaffold {
s.apps[name] = migration s.apps[name] = migration
return s return s