TMP: codetables
Some checks failed
CI / build-docker (push) Successful in 3s
CI / build-docker-bootstrap (push) Has been skipped
CI / release-test (push) Failing after 9s

This commit is contained in:
2026-03-19 23:36:51 -07:00
parent f8664ed514
commit 01e37a0e07
8 changed files with 208 additions and 3 deletions

View File

@@ -8,9 +8,15 @@ import (
// Column represents a single column in a table.
type Column struct {
TableName string `db:"table_name"`
Name string `db:"column_name"`
Type string `db:"column_type"`
// TableName is the name of the SQLite table this column belongs to.
TableName string `db:"table_name"`
// Name is the SQLite column name.
Name string `db:"column_name"`
// Type is the SQLite type this column contains.
Type string `db:"column_type"`
IsNotNull bool `db:"notnull"`
HasDefaultValue bool `db:"has_default_value"`
DefaultValue string `db:"dflt_value"`

View File

@@ -1,7 +1,12 @@
package schema
import (
"fmt"
"slices"
"sort"
"git.offline-twitter.com/offline-labs/gas-stack/pkg/flowutils"
"github.com/jmoiron/sqlx"
)
// Table is a single SQLite table.
@@ -61,3 +66,11 @@ func (t Table) HasAutoTimestamps() (hasCreatedAt bool, hasUpdatedAt bool) {
}
return
}
func (t Table) GetCodeTableValues(db *sqlx.DB) (ret []string) {
if !slices.ContainsFunc(t.Columns, func(c Column) bool { return c.Name == "name" }) {
panic("not a code table")
}
flowutils.PanicIf(db.Select(&ret, fmt.Sprintf("select name from %s", t.TableName)))
return
}