Documentation
¶
Overview ¶
Package sqlitetable writes rows described by query.ColumnDef into SQLite tables that a `sql` profile can read back under the declared column names.
Columns are stored positionally ("c0", "c1", …) and aliased on the way out, so a declared name is never an identifier the table itself has to carry — any string a profile can name a column is a name this package can store.
Index ¶
- Constants
- func DecodeStructured(columns []query.ColumnDef, row query.Row) error
- func FormatTime(at time.Time) string
- func IsStructured(columnType query.ColumnType) bool
- func ProfileColumns(columns []query.ColumnDef) []query.ColumnDef
- func QuoteIdentifier(value string) string
- func Type(columnType query.ColumnType) string
- func Value(columnType query.ColumnType, value any) (any, error)
- func Write(ctx context.Context, database Execer, table Table, rows []query.Row) error
- type Execer
- type Table
Constants ¶
const TimeLayout = "2006-01-02T15:04:05.000000000Z07:00"
TimeLayout is how an instant is stored, and how a bound compared against a stored instant must be bound. SQLite has no time type, so instants are TEXT compared as text, and text only orders as time when every value is written to the same width in the same zone: RFC3339Nano drops trailing zeros, so "…05Z" would sort after "…05.5Z", and the driver's rendering of a bound time.Time is Go's String(), which sorts before every stored value of its day.
Variables ¶
This section is empty.
Functions ¶
func DecodeStructured ¶
DecodeStructured parses the JSON text of every structured column in row in place, so a row read back holds the value that was written.
func IsStructured ¶
func IsStructured(columnType query.ColumnType) bool
IsStructured reports whether a column type is stored as JSON text.
func ProfileColumns ¶
ProfileColumns are the columns a profile over the table declares: each structured column reads its stored JSON text back as the value it encodes.
func QuoteIdentifier ¶
QuoteIdentifier quotes a SQLite identifier.
func Type ¶
func Type(columnType query.ColumnType) string
Type is the SQLite column type a declared column type is stored as. A boolean is declared BOOLEAN rather than INTEGER: SQLite stores both as 0/1, but the driver reads a BOOLEAN column back as a Go bool, so a profile over the table returns true/false rather than a number.
Types ¶
type Execer ¶
type Execer interface {
ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
}
Execer is what writing a table needs from a connection: a *sql.DB or a *sql.Tx.
type Table ¶
type Table struct {
Name string
Columns []query.ColumnDef
// PrimaryKey names the declared columns that together identify a row.
PrimaryKey []string
// Unique names declared columns that each get their own unique index.
Unique []string
}
Table is one SQLite table and the declared columns it stores.
func (Table) Insert ¶
Insert appends rows to the existing table. A row key the table does not declare is not stored; a declared column the row lacks is stored as NULL.