Documentation
¶
Overview ¶
Package sqladapter provides generic SQL dialect handling and a base relational adapter.
Index ¶
- type BaseAdapter
- func (a *BaseAdapter) Count(ctx context.Context, modelName string, where []adapter.Condition) (int64, error)
- func (a *BaseAdapter) Create(ctx context.Context, modelName string, data map[string]any) (map[string]any, error)
- func (a *BaseAdapter) DB() *sql.DB
- func (a *BaseAdapter) Delete(ctx context.Context, modelName string, where []adapter.Condition) (int64, error)
- func (a *BaseAdapter) Dialect() Dialect
- func (a *BaseAdapter) ExportSchema(ctx context.Context) ([]string, error)
- func (a *BaseAdapter) FindMany(ctx context.Context, q adapter.Query) ([]map[string]any, error)
- func (a *BaseAdapter) FindOne(ctx context.Context, modelName string, where []adapter.Condition) (map[string]any, error)
- func (a *BaseAdapter) Migrate(ctx context.Context) error
- func (a *BaseAdapter) RegisterSchema(ctx context.Context, s *schema.Schema) error
- func (a *BaseAdapter) Transaction(ctx context.Context, fn func(ctx context.Context, tx adapter.Adapter) error) error
- func (a *BaseAdapter) Update(ctx context.Context, modelName string, where []adapter.Condition, ...) (int64, error)
- type Dialect
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseAdapter ¶
type BaseAdapter struct {
// contains filtered or unexported fields
}
BaseAdapter is the shared SQL adapter engine implementing adapter.Adapter.
func New ¶
func New(db *sql.DB, d Dialect) *BaseAdapter
New creates a new BaseAdapter configured with the provided sql.DB and Dialect.
func (*BaseAdapter) Count ¶
func (a *BaseAdapter) Count(ctx context.Context, modelName string, where []adapter.Condition) (int64, error)
Count returns the number of matching records.
func (*BaseAdapter) Create ¶
func (a *BaseAdapter) Create(ctx context.Context, modelName string, data map[string]any) (map[string]any, error)
Create inserts a single record into the database table for the given model.
func (*BaseAdapter) DB ¶
func (a *BaseAdapter) DB() *sql.DB
DB returns the underlying database pool.
func (*BaseAdapter) Delete ¶
func (a *BaseAdapter) Delete(ctx context.Context, modelName string, where []adapter.Condition) (int64, error)
Delete removes records matching conditions.
func (*BaseAdapter) Dialect ¶
func (a *BaseAdapter) Dialect() Dialect
Dialect returns the active SQL dialect.
func (*BaseAdapter) ExportSchema ¶
func (a *BaseAdapter) ExportSchema(ctx context.Context) ([]string, error)
ExportSchema returns the raw DDL statements for creating all tables and indexes.
func (*BaseAdapter) FindOne ¶
func (a *BaseAdapter) FindOne(ctx context.Context, modelName string, where []adapter.Condition) (map[string]any, error)
FindOne returns the first record matching the given conditions.
func (*BaseAdapter) Migrate ¶
func (a *BaseAdapter) Migrate(ctx context.Context) error
Migrate applies DDL to create missing tables, columns and indexes based on the compiled schema.
func (*BaseAdapter) RegisterSchema ¶
RegisterSchema records the compiled schema into the adapter.
type Dialect ¶
type Dialect interface {
Name() string
Placeholder(index int) string
Quote(name string) string
DataType(dt schema.DataType) string
MapError(err error) error
}
Dialect abstracts SQL syntax differences across database engines.
var MySQL Dialect = &mysqlDialect{}
MySQL returns the MySQL dialect implementation.
var Postgres Dialect = &postgresDialect{}
Postgres returns the PostgreSQL dialect implementation.
var SQLite Dialect = &sqliteDialect{}
SQLite returns the SQLite dialect implementation.