Documentation
¶
Overview ¶
Package ops provides high-level operations for working with CommitDB databases and tables.
The ops package sits between the SQL engine (engine/) and the persistence layer (persistence/), providing convenient abstractions for common database operations.
DatabaseOp ¶
DatabaseOp wraps database-level operations:
dbOp, err := ops.GetDatabase("mydb", persistence)
tables := dbOp.TableNames() // List all tables
dbOp.DropDatabase(identity) // Drop database
dbOp.Restore(transaction) // Restore to point in time
TableOp ¶
TableOp wraps table-level operations for CRUD and scanning:
tableOp, err := ops.GetTable("mydb", "users", persistence)
// Read operations
value, exists := tableOp.Get("key") // Get raw bytes
str, exists := tableOp.GetString("key") // Get as string
num, exists, _ := tableOp.GetInt("key") // Get as int
keys := tableOp.Keys() // List all keys
count := tableOp.Count() // Count records
// Write operations
tableOp.Put("key", []byte("value"), identity)
tableOp.PutAll(map[string][]byte{...}, identity)
tableOp.Delete("key", identity)
// Scanning with optional filter
for key, value := range tableOp.Scan() {
// process all records
}
for key, value := range tableOp.ScanWithFilter(func(k string, v []byte) bool {
return strings.HasPrefix(k, "user_")
}) {
// process filtered records
}
Architecture ¶
The layering is:
SQL Parser (internal/sql/)
↓
SQL Engine (engine/)
↓
Operations (internal/ops/) ← This package
↓
Persistence (persistence/)
↓
Git Storage (go-git)
Index ¶
- type DatabaseOp
- type TableOp
- func (op *TableOp) CopyFrom(source *TableOp, identity core.Identity) (txn persistence.Transaction, err error)
- func (op *TableOp) Count() int
- func (op *TableOp) Delete(key string, identity core.Identity) (txn persistence.Transaction, err error)
- func (op *TableOp) DropTable(identity core.Identity) (txn persistence.Transaction, err error)
- func (op *TableOp) Get(key string) (value []byte, exists bool)
- func (op *TableOp) GetInt(key string) (valueAsInt int, exists bool, err error)
- func (op *TableOp) GetString(key string) (valueAsString string, exists bool)
- func (op *TableOp) Keys() []string
- func (op *TableOp) PrimaryKey() (pk *string, err error)
- func (op *TableOp) Put(key string, value []byte, identity core.Identity) (txn persistence.Transaction, err error)
- func (op *TableOp) PutAll(records map[string][]byte, identity core.Identity) (txn persistence.Transaction, err error)
- func (op *TableOp) Restore(asof persistence.Transaction) error
- func (op *TableOp) Scan() iter.Seq2[string, []byte]
- func (op *TableOp) ScanWithFilter(filterExpr func(key string, value []byte) bool) iter.Seq2[string, []byte]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DatabaseOp ¶
type DatabaseOp struct {
Database core.Database
Persistence *persistence.Persistence
}
func CreateDatabase ¶
func CreateDatabase(database core.Database, p *persistence.Persistence, identity core.Identity) (*persistence.Transaction, *DatabaseOp, error)
func GetDatabase ¶
func GetDatabase(name string, p *persistence.Persistence) (*DatabaseOp, error)
func (*DatabaseOp) DropDatabase ¶
func (op *DatabaseOp) DropDatabase(identity core.Identity) (txn persistence.Transaction, err error)
func (*DatabaseOp) Restore ¶
func (op *DatabaseOp) Restore(asof persistence.Transaction) error
func (*DatabaseOp) TableNames ¶
func (op *DatabaseOp) TableNames() []string
type TableOp ¶
type TableOp struct {
Table core.Table
Persistence *persistence.Persistence
}
func CreateTable ¶
func CreateTable(table core.Table, p *persistence.Persistence, identity core.Identity) (*persistence.Transaction, *TableOp, error)
func GetTable ¶
func GetTable(database string, tableName string, p *persistence.Persistence) (*TableOp, error)
func (*TableOp) CopyFrom ¶
func (op *TableOp) CopyFrom(source *TableOp, identity core.Identity) (txn persistence.Transaction, err error)
CopyFrom copies all records from source table into this table in a single atomic transaction. Memory-efficient: records are streamed row-by-row without loading all into Go memory.
func (*TableOp) Delete ¶
func (op *TableOp) Delete(key string, identity core.Identity) (txn persistence.Transaction, err error)
func (*TableOp) DropTable ¶
func (op *TableOp) DropTable(identity core.Identity) (txn persistence.Transaction, err error)
func (*TableOp) PrimaryKey ¶
func (*TableOp) Put ¶
func (op *TableOp) Put(key string, value []byte, identity core.Identity) (txn persistence.Transaction, err error)
func (*TableOp) PutAll ¶
func (op *TableOp) PutAll(records map[string][]byte, identity core.Identity) (txn persistence.Transaction, err error)
func (*TableOp) Restore ¶
func (op *TableOp) Restore(asof persistence.Transaction) error
Click to show internal directories.
Click to hide internal directories.