Documentation
¶
Overview ¶
Package adapter defines the generic, schema-driven persistence contracts for GoModularAuth.
Unlike static domain repository interfaces, an Adapter executes generic CRUD operations parameterized by model name and declarative query conditions. This decouples storage drivers (PostgreSQL, SQLite, MySQL, Memory) from individual plugin domain types.
Index ¶
- Variables
- type Adapter
- type Condition
- func Eq(field string, val any) Condition
- func Gt(field string, val any) Condition
- func Gte(field string, val any) Condition
- func In(field string, vals ...any) Condition
- func IsNotNull(field string) Condition
- func IsNull(field string) Condition
- func Lt(field string, val any) Condition
- func Lte(field string, val any) Condition
- func Ne(field string, val any) Condition
- type Operator
- type Query
- type SchemaExporter
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned when a record matching the query criteria does not exist. ErrNotFound = errors.New("adapter: record not found") // ErrConflict is returned when an insert or update violates a unique constraint or primary key. ErrConflict = errors.New("adapter: record conflict") )
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter interface {
// RegisterSchema provides the compiled schema to the adapter, allowing
// it to map fields, understand constraints, and prepare statements or tables.
RegisterSchema(ctx context.Context, s *schema.Schema) error
// Create inserts a single record into the given model. It returns the persisted
// data (including database defaults or auto-generated IDs).
// Returns ErrConflict on unique constraint violations.
Create(ctx context.Context, model string, data map[string]any) (map[string]any, error)
// FindOne retrieves the first record matching all conditions, or ErrNotFound if none match.
FindOne(ctx context.Context, model string, where []Condition) (map[string]any, error)
// FindMany retrieves all records matching the query criteria.
FindMany(ctx context.Context, q Query) ([]map[string]any, error)
// Update modifies records matching the conditions and returns the number of rows affected.
Update(ctx context.Context, model string, where []Condition, update map[string]any) (int64, error)
// Delete removes records matching the conditions and returns the number of rows affected.
Delete(ctx context.Context, model string, where []Condition) (int64, error)
// Count returns the number of records matching the given conditions.
Count(ctx context.Context, model string, where []Condition) (int64, error)
// Transaction executes fn atomically within a database transaction.
// Nested transactions join the parent transaction.
Transaction(ctx context.Context, fn func(ctx context.Context, tx Adapter) error) error
}
Adapter is the polymorphic storage engine interface implemented by databases.
All database adapters (Postgres, SQLite, MySQL, Memory) implement this single interface, allowing plugins to declare new models and fields without needing engine-specific repository implementations.
type Condition ¶
Condition represents a single predicate applied to a model field.
type Operator ¶
type Operator string
Operator represents a logical comparison operator for query conditions.
type SchemaExporter ¶
type SchemaExporter interface {
// ExportSchema returns the raw DDL statements required to provision the registered schema.
ExportSchema(ctx context.Context) ([]string, error)
}
SchemaExporter is an optional capability interface implemented by storage adapters that can export their compiled schema definitions as executable DDL statements (e.g. SQL, SurrealQL).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package bridge implements a store.Store adapter on top of adapter.Adapter.
|
Package bridge implements a store.Store adapter on top of adapter.Adapter. |
|
Package memory provides an in-memory implementation of adapter.Adapter.
|
Package memory provides an in-memory implementation of adapter.Adapter. |
|
Package sqladapter provides generic SQL dialect handling and a base relational adapter.
|
Package sqladapter provides generic SQL dialect handling and a base relational adapter. |