sqladapter

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package sqladapter provides generic SQL dialect handling and a base relational adapter.

Index

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) FindMany

func (a *BaseAdapter) FindMany(ctx context.Context, q adapter.Query) ([]map[string]any, error)

FindMany returns all records matching query conditions.

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

func (a *BaseAdapter) RegisterSchema(ctx context.Context, s *schema.Schema) error

RegisterSchema records the compiled schema into the adapter.

func (*BaseAdapter) Transaction

func (a *BaseAdapter) Transaction(ctx context.Context, fn func(ctx context.Context, tx adapter.Adapter) error) error

Transaction executes fn atomically using sqltx.

func (*BaseAdapter) Update

func (a *BaseAdapter) Update(ctx context.Context, modelName string, where []adapter.Condition, update map[string]any) (int64, error)

Update modifies records matching the conditions.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL