drivers

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Name          string
	Type          string
	Size          int
	Nullable      bool
	Default       any
	AutoIncrement bool
	Primary       bool
	Unique        bool
	Comment       string
}

Column represents a database column

type Condition

type Condition struct {
	Column   string
	Operator string
	Value    any
	Type     string // "and" or "or"
}

Condition represents a WHERE condition

type ConnectionConfig

type ConnectionConfig struct {
	Driver             string
	Host               string
	Port               string
	Database           string
	Username           string
	Password           string
	Charset            string
	Collation          string
	Prefix             string
	Schema             string
	SSLMode            string
	TimeZone           string
	MaxIdleConns       int
	MaxOpenConns       int
	ConnMaxLifetime    time.Duration
	ConnMaxIdleTime    time.Duration
	LogQueries         bool
	SlowQueryThreshold time.Duration
}

ConnectionConfig holds database connection settings

type Driver

type Driver interface {
	// Connection management
	Connect(config ConnectionConfig) error
	Close() error
	Ping() error
	DB() *sql.DB

	// Query execution
	Query(query string, args ...any) (*sql.Rows, error)
	QueryRow(query string, args ...any) *sql.Row
	Exec(query string, args ...any) (sql.Result, error)

	// Transaction support
	Begin() (*sql.Tx, error)
	BeginTx() (*sql.Tx, error)

	// Schema operations
	CreateTable(name string, definition func(*Table)) error
	DropTable(name string) error
	HasTable(name string) bool
	HasColumn(table, column string) bool

	// Driver-specific
	Grammar() QueryGrammar
	DriverName() string
}

Driver defines the interface for all database drivers

func NewPostgresDriver

func NewPostgresDriver() Driver

NewPostgresDriver creates a new PostgreSQL driver instance

func NewSQLiteDriver

func NewSQLiteDriver() Driver

NewSQLiteDriver creates a new SQLite driver instance

type Index

type Index struct {
	Name    string
	Columns []string
	Unique  bool
	Type    string // BTREE, HASH, etc.
}

Index represents a database index

type Join

type Join struct {
	Type      string // INNER, LEFT, RIGHT, FULL
	Table     string
	On        string
	Condition []Condition
}

Join represents a JOIN clause

type Order

type Order struct {
	Column    string
	Direction string
}

Order represents an ORDER BY clause

type PostgresDriver

type PostgresDriver struct {
	// contains filtered or unexported fields
}

PostgresDriver implements the Driver interface for PostgreSQL

func (*PostgresDriver) Begin

func (d *PostgresDriver) Begin() (*sql.Tx, error)

Begin starts a transaction

func (*PostgresDriver) BeginTx

func (d *PostgresDriver) BeginTx() (*sql.Tx, error)

BeginTx starts a transaction with options

func (*PostgresDriver) Close

func (d *PostgresDriver) Close() error

Close closes the database connection

func (*PostgresDriver) Connect

func (d *PostgresDriver) Connect(config ConnectionConfig) error

Connect establishes a connection to PostgreSQL database

func (*PostgresDriver) CreateTable

func (d *PostgresDriver) CreateTable(name string, definition func(*Table)) error

CreateTable creates a new table

func (*PostgresDriver) DB

func (d *PostgresDriver) DB() *sql.DB

DB returns the underlying *sql.DB instance

func (*PostgresDriver) DriverName

func (d *PostgresDriver) DriverName() string

DriverName returns the driver name

func (*PostgresDriver) DropTable

func (d *PostgresDriver) DropTable(name string) error

DropTable drops a table

func (*PostgresDriver) Exec

func (d *PostgresDriver) Exec(query string, args ...any) (sql.Result, error)

Exec executes a query that doesn't return rows

func (*PostgresDriver) Grammar

func (d *PostgresDriver) Grammar() QueryGrammar

Grammar returns the PostgreSQL query grammar

func (*PostgresDriver) HasColumn

func (d *PostgresDriver) HasColumn(table, column string) bool

HasColumn checks if a column exists in a table

func (*PostgresDriver) HasTable

func (d *PostgresDriver) HasTable(name string) bool

HasTable checks if a table exists

func (*PostgresDriver) Ping

func (d *PostgresDriver) Ping() error

Ping verifies the connection to the database

func (*PostgresDriver) Query

func (d *PostgresDriver) Query(query string, args ...any) (*sql.Rows, error)

Query executes a query that returns rows

func (*PostgresDriver) QueryRow

func (d *PostgresDriver) QueryRow(query string, args ...any) *sql.Row

QueryRow executes a query that returns at most one row

type PostgresGrammar

type PostgresGrammar struct{}

PostgresGrammar implements QueryGrammar for PostgreSQL

func (*PostgresGrammar) CompileCreateTable

func (g *PostgresGrammar) CompileCreateTable(name string, table *Table) string

CompileCreateTable compiles a CREATE TABLE query for PostgreSQL

func (*PostgresGrammar) CompileDelete

func (g *PostgresGrammar) CompileDelete(table string, conditions []Condition) (string, []any)

CompileDelete compiles a DELETE query for PostgreSQL

func (*PostgresGrammar) CompileDropTable

func (g *PostgresGrammar) CompileDropTable(name string) string

CompileDropTable compiles a DROP TABLE query for PostgreSQL

func (*PostgresGrammar) CompileHasColumn

func (g *PostgresGrammar) CompileHasColumn(table, column string) string

CompileHasColumn compiles a query to check if column exists in PostgreSQL

func (*PostgresGrammar) CompileHasTable

func (g *PostgresGrammar) CompileHasTable(name string) string

CompileHasTable compiles a query to check if table exists in PostgreSQL

func (*PostgresGrammar) CompileInsert

func (g *PostgresGrammar) CompileInsert(table string, columns []string, values [][]any) (string, []any)

CompileInsert compiles an INSERT query for PostgreSQL

func (*PostgresGrammar) CompileSelect

func (g *PostgresGrammar) CompileSelect(query *SelectQuery) (string, []any)

CompileSelect compiles a SELECT query for PostgreSQL

func (*PostgresGrammar) CompileUpdate

func (g *PostgresGrammar) CompileUpdate(table string, values map[string]any, conditions []Condition) (string, []any)

CompileUpdate compiles an UPDATE query for PostgreSQL

func (*PostgresGrammar) Placeholder

func (g *PostgresGrammar) Placeholder(index int) string

Placeholder returns the placeholder for prepared statements in PostgreSQL

func (*PostgresGrammar) QuoteIdentifier

func (g *PostgresGrammar) QuoteIdentifier(name string) string

QuoteIdentifier quotes a database identifier for PostgreSQL

func (*PostgresGrammar) QuoteString

func (g *PostgresGrammar) QuoteString(value string) string

QuoteString quotes a string value for PostgreSQL

type QueryGrammar

type QueryGrammar interface {
	// SELECT operations
	CompileSelect(query *SelectQuery) (string, []any)
	CompileInsert(table string, columns []string, values [][]any) (string, []any)
	CompileUpdate(table string, values map[string]any, conditions []Condition) (string, []any)
	CompileDelete(table string, conditions []Condition) (string, []any)

	// Schema operations
	CompileCreateTable(name string, table *Table) string
	CompileDropTable(name string) string
	CompileHasTable(name string) string
	CompileHasColumn(table, column string) string

	// Utilities
	QuoteIdentifier(name string) string
	QuoteString(value string) string
	Placeholder(index int) string
}

QueryGrammar defines SQL dialect-specific query building

type SQLiteDriver

type SQLiteDriver struct {
	// contains filtered or unexported fields
}

SQLiteDriver implements the Driver interface for SQLite

func (*SQLiteDriver) Begin

func (d *SQLiteDriver) Begin() (*sql.Tx, error)

Begin starts a transaction

func (*SQLiteDriver) BeginTx

func (d *SQLiteDriver) BeginTx() (*sql.Tx, error)

BeginTx starts a transaction with options

func (*SQLiteDriver) Close

func (d *SQLiteDriver) Close() error

Close closes the database connection

func (*SQLiteDriver) Connect

func (d *SQLiteDriver) Connect(config ConnectionConfig) error

Connect establishes a connection to SQLite database

func (*SQLiteDriver) CreateTable

func (d *SQLiteDriver) CreateTable(name string, definition func(*Table)) error

CreateTable creates a new table

func (*SQLiteDriver) DB

func (d *SQLiteDriver) DB() *sql.DB

DB returns the underlying *sql.DB instance

func (*SQLiteDriver) DriverName

func (d *SQLiteDriver) DriverName() string

DriverName returns the driver name

func (*SQLiteDriver) DropTable

func (d *SQLiteDriver) DropTable(name string) error

DropTable drops a table

func (*SQLiteDriver) Exec

func (d *SQLiteDriver) Exec(query string, args ...any) (sql.Result, error)

Exec executes a query that doesn't return rows

func (*SQLiteDriver) Grammar

func (d *SQLiteDriver) Grammar() QueryGrammar

Grammar returns the SQLite query grammar

func (*SQLiteDriver) HasColumn

func (d *SQLiteDriver) HasColumn(table, column string) bool

HasColumn checks if a column exists in a table

func (*SQLiteDriver) HasTable

func (d *SQLiteDriver) HasTable(name string) bool

HasTable checks if a table exists

func (*SQLiteDriver) Ping

func (d *SQLiteDriver) Ping() error

Ping verifies the connection to the database

func (*SQLiteDriver) Query

func (d *SQLiteDriver) Query(query string, args ...any) (*sql.Rows, error)

Query executes a query that returns rows

func (*SQLiteDriver) QueryRow

func (d *SQLiteDriver) QueryRow(query string, args ...any) *sql.Row

QueryRow executes a query that returns at most one row

type SQLiteGrammar

type SQLiteGrammar struct{}

SQLiteGrammar implements QueryGrammar for SQLite

func (*SQLiteGrammar) CompileCreateTable

func (g *SQLiteGrammar) CompileCreateTable(name string, table *Table) string

CompileCreateTable compiles a CREATE TABLE query

func (*SQLiteGrammar) CompileDelete

func (g *SQLiteGrammar) CompileDelete(table string, conditions []Condition) (string, []any)

CompileDelete compiles a DELETE query

func (*SQLiteGrammar) CompileDropTable

func (g *SQLiteGrammar) CompileDropTable(name string) string

CompileDropTable compiles a DROP TABLE query

func (*SQLiteGrammar) CompileHasColumn

func (g *SQLiteGrammar) CompileHasColumn(table, column string) string

CompileHasColumn compiles a query to check if column exists

func (*SQLiteGrammar) CompileHasTable

func (g *SQLiteGrammar) CompileHasTable(name string) string

CompileHasTable compiles a query to check if table exists

func (*SQLiteGrammar) CompileInsert

func (g *SQLiteGrammar) CompileInsert(table string, columns []string, values [][]any) (string, []any)

CompileInsert compiles an INSERT query

func (*SQLiteGrammar) CompileSelect

func (g *SQLiteGrammar) CompileSelect(query *SelectQuery) (string, []any)

CompileSelect compiles a SELECT query

func (*SQLiteGrammar) CompileUpdate

func (g *SQLiteGrammar) CompileUpdate(table string, values map[string]any, conditions []Condition) (string, []any)

CompileUpdate compiles an UPDATE query

func (*SQLiteGrammar) Placeholder

func (g *SQLiteGrammar) Placeholder(index int) string

Placeholder returns the placeholder for prepared statements

func (*SQLiteGrammar) QuoteIdentifier

func (g *SQLiteGrammar) QuoteIdentifier(name string) string

QuoteIdentifier quotes a database identifier

func (*SQLiteGrammar) QuoteString

func (g *SQLiteGrammar) QuoteString(value string) string

QuoteString quotes a string value

type SelectQuery

type SelectQuery struct {
	Table         string
	Columns       []string
	Conditions    []Condition
	Orders        []Order
	Groups        []string
	Having        []Condition
	Limit         *int
	Offset        *int
	Joins         []Join
	Distinct      bool
	LockForUpdate bool
	SkipLocked    bool
}

SelectQuery represents a SELECT query structure

type Table

type Table struct {
	Name    string
	Columns []Column
	Indexes []Index
	Primary string
}

Table represents a database table structure

Jump to

Keyboard shortcuts

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