Documentation
¶
Overview ¶
Package zealql provides a lightweight in-memory SQLite wrapper that automatically infers schemas from map data and supports JSON columns with embedded JSON Schema comments.
Index ¶
- type Column
- type Database
- func (d *Database) Clone() (*Database, error)
- func (d *Database) Close() error
- func (d *Database) GetTable(name string) (*Table, bool)
- func (d *Database) Insert(name string, data any) (*Table, error)
- func (d *Database) ListTables() []string
- func (d *Database) Query(query string, args ...any) ([]map[string]any, error)
- type Preparer
- type SQLType
- type Table
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Column ¶
type Column struct {
Name string
Type SQLType
JSONSchema *jsonschema.Schema // Optional: Schema for structured JSON data in TEXT columns.
}
Column represents a single database column with an optional inferred JSON Schema.
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database represents an in-memory data manipulation database that tracks inferred table schemas.
func NewDatabase ¶
NewDatabase initializes a new in-memory SQLite database. It returns an error if the database driver is not available or fails to initialize.
func (*Database) Clone ¶
Clone creates a complete deep copy of the database, including all tables, data, and inferred schema metadata.
func (*Database) GetTable ¶
GetTable returns a table definition by its name if it was created via Insert.
func (*Database) Insert ¶
Insert infers a table schema from data (a slice of maps), creates the table if it doesn't exist yet and inserts the rows. If the table already exists, the inferred schema must be compatible with the existing one. The whole operation is atomic: either the table is created and all rows are inserted, or nothing changes. It is safe for concurrent use.
func (*Database) ListTables ¶
type Table ¶
Table represents a SQLite table definition, including its columns and logic for SQL generation and data ingestion.
func InferTable ¶
InferTable analyzes a slice of map data to determine the most appropriate SQLite table schema. It handles type promotion and JSON schema inference for structured fields.
func (*Table) Compatible ¶
Compatible checks if the provided table has an identical schema (column names and types) to the current table. It assumes columns in both tables are sorted by name.
func (*Table) GenerateInsertSQL ¶
GenerateInsertSQL creates an INSERT INTO statement template with question mark (?) placeholders for all table columns.