Documentation
¶
Overview ¶
Package powder is the Go client for the Powder engine.
It talks to the Rust core through the stable C ABI exported by the powder-ffi crate (powder_ffi.dll / libpowder_ffi.so / .dylib). Query results arrive as the zero-copy PCB columnar buffer and are decoded in pure Go.
Load the native library once, then connect:
if err := powder.Load("/path/to/powder_ffi.dll"); err != nil { ... }
db, err := powder.Connect("sqlite::memory:")
defer db.Close()
batch, err := db.Query("SELECT id, name FROM users WHERE id >= ?", 2)
name := batch.Column("name")
for r := 0; r < batch.NumRows(); r++ { fmt.Println(name.String(r)) }
Index ¶
- func Load(path string) error
- type Batch
- type Client
- func (c *Client) Close() error
- func (c *Client) Exec(sql string, params ...any) (int64, error)
- func (c *Client) Orm(schemaJSON string) (*Orm, error)
- func (c *Client) Query(sql string, params ...any) (*Batch, error)
- func (c *Client) Run(q *Query) (*Batch, error)
- func (c *Client) Transaction(fn func(tx *Client) error) (err error)
- type Column
- func (c *Column) Bool(row int) bool
- func (c *Column) Float64(row int) float64
- func (c *Column) Get(row int) any
- func (c *Column) Int64(row int) int64
- func (c *Column) IsValid(row int) bool
- func (c *Column) Len() int
- func (c *Column) Name() string
- func (c *Column) String(row int) string
- func (c *Column) Type() DataType
- type DataType
- type M
- type Orm
- type OrmTable
- func (t *OrmTable) Aggregate(fn, column string, where M) (*float64, error)
- func (t *OrmTable) All() ([]M, error)
- func (t *OrmTable) Count(where M) (int64, error)
- func (t *OrmTable) Create(data M) (int64, error)
- func (t *OrmTable) CreateMany(rows []M) (int64, error)
- func (t *OrmTable) Delete(where M) (int64, error)
- func (t *OrmTable) DeleteAll() (int64, error)
- func (t *OrmTable) Exists(where M) (bool, error)
- func (t *OrmTable) FindFirst(opts M) (M, error)
- func (t *OrmTable) FindMany(opts M) ([]M, error)
- func (t *OrmTable) GroupBy(opts M) ([]M, error)
- func (t *OrmTable) Update(where M, data M) (int64, error)
- type Query
- func (q *Query) Filter(predicate string, params ...any) *Query
- func (q *Query) Limit(n int64) *Query
- func (q *Query) Offset(n int64) *Query
- func (q *Query) OrderBy(column, direction string) *Query
- func (q *Query) Params() []any
- func (q *Query) SQL() string
- func (q *Query) Select(columns ...string) *Query
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Batch ¶
type Batch struct {
// contains filtered or unexported fields
}
Batch is a decoded columnar result set.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a database connection. It is safe for use from one goroutine at a time; the Rust core serializes access to its single connection.
func (*Client) Transaction ¶
Transaction runs fn in a transaction. The outermost call issues BEGIN IMMEDIATE + COMMIT/ROLLBACK; nested calls use SAVEPOINT / RELEASE / ROLLBACK TO, so an inner transaction that fails rolls back only its own work while an outer one can still commit.
type Column ¶
type Column struct {
// contains filtered or unexported fields
}
Column is a single decoded PCB column. Values are read straight out of the little-endian payload; nothing is materialized until you ask for it.
type DataType ¶
type DataType uint8
DataType is one of the four physical column types carried by PCB.
type Orm ¶
type Orm struct {
// contains filtered or unexported fields
}
Orm is the model layer over a Client: the same operation semantics as the TS/Python ORMs, executed by the shared Rust engine. Build one from the `powder.schema.json` text; then address tables by name.
orm, err := db.Orm(schemaJSON)
users := orm.Table("users")
rows, err := users.FindMany(powder.M{
"where": powder.M{"active": true, "score": powder.M{"gte": 5}},
"orderBy": powder.M{"score": "desc"},
"limit": 10,
})
type OrmTable ¶
type OrmTable struct {
// contains filtered or unexported fields
}
OrmTable is the unified CRUD surface of Powder ORM for one table.
func (*OrmTable) Aggregate ¶
Aggregate runs SUM/AVG/MIN/MAX over one column; nil when no rows match.
func (*OrmTable) CreateMany ¶
CreateMany bulk-INSERTs with multi-row VALUES, chunked; every row must carry the same columns as the first.
func (*OrmTable) FindMany ¶
FindMany returns rows matching opts (`where`, `orderBy`, `limit`, `offset`, `include`, `join` — same keys as the TS/Python ORMs). Pass nil for all rows.
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query is a fluent, injection-safe SELECT builder — the Go mirror of the Rust/TypeScript/Java builders. Values go through bound parameters; only identifiers you supply are interpolated.
q := powder.Table("users").Select("id", "name").
Filter("score >= ?", 5.0).OrderBy("score", "DESC").Limit(10)
batch, err := db.Run(q)
func (*Query) Filter ¶
Filter adds a WHERE predicate; supply one "?" per parameter. Repeated calls are ANDed together.