define

package
v4.0.1-ai Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Debug bool

Debug flag for enabling debug mode

Functions

func RegisterFactory

func RegisterFactory(driver string, factory SQLFactory)

RegisterFactory registers a SQL factory for a specific driver

func UnregisterFactory

func UnregisterFactory(driver string)

UnregisterFactory removes a SQL factory for a specific driver

Types

type Condition

type Condition struct {
	Field string
	Op    string
	Value interface{}
}

Condition represents a SQL condition

type ITableModel

type ITableModel interface {
	// TableName returns the custom table name
	TableName() string
	// CreateSql returns the custom CREATE TABLE SQL statement
	CreateSql() string
}

ITableModel defines the interface for custom table models

type Result

type Result struct {
	ID       int64
	Affected int64
}

Result implements sql.Result interface

func (*Result) LastInsertId

func (r *Result) LastInsertId() (int64, error)

LastInsertId returns the last inserted ID

func (*Result) RowsAffected

func (r *Result) RowsAffected() (int64, error)

RowsAffected returns the number of rows affected

type SQLFactory

type SQLFactory interface {
	// Connect creates a new database connection
	Connect(dsn string) (*sql.DB, error)

	// BuildSelect builds a SELECT query
	BuildSelect(table string, fields []string, conditions []*Condition, orderBy string, limit, offset int) (string, []interface{})

	// BuildUpdate builds an UPDATE query
	BuildUpdate(table string, fields map[string]interface{}, conditions []*Condition) (string, []interface{})

	// BuildInsert builds an INSERT query
	BuildInsert(table string, fields map[string]interface{}) (string, []interface{})

	// BuildBatchInsert builds a batch INSERT query
	BuildBatchInsert(table string, values []map[string]interface{}) (string, []interface{})

	// BuildDelete builds a DELETE query
	BuildDelete(table string, conditions []*Condition) (string, []interface{})

	// BuildCreateTable builds a CREATE TABLE query
	BuildCreateTable(table string, modelType reflect.Type) string
}

SQLFactory defines the interface for SQL generation

func GetFactory

func GetFactory(driver string) (SQLFactory, error)

GetFactory returns the SQL factory for a specific driver

Jump to

Keyboard shortcuts

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