initial commit

This commit is contained in:
2026-09-01 00:13:01 +01:00
commit efa486fea8
9 changed files with 491 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
package sqaffold
import (
"context"
"database/sql"
"code.aneur.in/go/record"
"code.aneur.in/go/version"
)
type Scaffold struct {
ctx context.Context
conn *sql.DB
apps map[string]version.Migration
}
func (s *Scaffold) Exec(query string, args ...any) (sql.Result, error) {
return s.conn.ExecContext(s.ctx, query, args...)
}
func (s *Scaffold) Query(query string, args ...any) ([]record.Record, error) {
rows, err := s.conn.QueryContext(s.ctx, query, args...)
if err != nil {
return nil, Err(err)
}
return ScanRecords(rows)
}
func (s *Scaffold) QueryOne(query string, args ...any) (record.Record, error) {
rows, err := s.conn.QueryContext(s.ctx, query, args...)
if err != nil {
return nil, Err(err)
}
return ScanOneRecord(rows)
}
func (s *Scaffold) WithApp(name string, migration version.Migration) *Scaffold {
s.apps[name] = migration
return s
}
func NewScaffold(ctx context.Context, conn *sql.DB) *Scaffold {
s := &Scaffold{
ctx: ctx,
conn: conn,
apps: map[string]version.Migration{},
}
return s
}