database

package
v0.0.0-...-14535a3 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotConnected  = fmt.Errorf("database not connected")
	ErrTableNotFound = fmt.Errorf("table not found")
)

Common error types

Functions

This section is empty.

Types

type Column

type Column struct {
	Name            string
	DataType        string
	FullDataType    string // includes precision, scale, etc.
	IsNullable      bool
	DefaultValue    *string
	IsPrimaryKey    bool
	IsAutoIncrement bool
	Comment         string
	OrdinalPosition int
}

Column represents a table column

type Driver

type Driver interface {
	// Connection management
	Connect(ctx context.Context) error
	Close() error
	Ping(ctx context.Context) error

	// Schema operations
	GetTables(ctx context.Context) ([]Table, error)
	GetTableSchema(ctx context.Context, tableName string) (*TableSchema, error)
	GetPrimaryKey(ctx context.Context, tableName string) ([]string, error)

	// Data operations
	Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	Execute(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

	// Batch operations
	BulkInsert(ctx context.Context, tableName string, columns []string, rows [][]interface{}) error

	// Transaction support
	BeginTx(ctx context.Context) (*sql.Tx, error)

	// Metadata
	DriverName() string
	DatabaseName() string
}

Driver defines the interface for database operations

func NewDriver

func NewDriver(cfg *config.DatabaseConfig) (Driver, error)

DriverFactory creates a new database driver based on configuration

type ForeignKey

type ForeignKey struct {
	Name              string
	Columns           []string
	ReferencedTable   string
	ReferencedColumns []string
	OnUpdate          string
	OnDelete          string
}

ForeignKey represents a foreign key constraint

type Index

type Index struct {
	Name      string
	Columns   []string
	IsUnique  bool
	IsPrimary bool
}

Index represents a table index

type MySQLDriver

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

MySQLDriver implements Driver interface for MySQL/MariaDB

func NewMySQLDriver

func NewMySQLDriver(cfg *config.DatabaseConfig) (*MySQLDriver, error)

NewMySQLDriver creates a new MySQL driver

func (*MySQLDriver) BeginTx

func (d *MySQLDriver) BeginTx(ctx context.Context) (*sql.Tx, error)

BeginTx starts a new transaction

func (*MySQLDriver) BulkInsert

func (d *MySQLDriver) BulkInsert(ctx context.Context, tableName string, columns []string, rows [][]interface{}) error

BulkInsert performs bulk insert operation

func (*MySQLDriver) Close

func (d *MySQLDriver) Close() error

Close closes the database connection

func (*MySQLDriver) Connect

func (d *MySQLDriver) Connect(ctx context.Context) error

Connect establishes a connection to MySQL

func (*MySQLDriver) DatabaseName

func (d *MySQLDriver) DatabaseName() string

DatabaseName returns the database name

func (*MySQLDriver) DriverName

func (d *MySQLDriver) DriverName() string

DriverName returns the driver name

func (*MySQLDriver) Execute

func (d *MySQLDriver) Execute(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

Execute executes a query that doesn't return rows

func (*MySQLDriver) GetPrimaryKey

func (d *MySQLDriver) GetPrimaryKey(ctx context.Context, tableName string) ([]string, error)

GetPrimaryKey returns the primary key columns of a table

func (*MySQLDriver) GetTableSchema

func (d *MySQLDriver) GetTableSchema(ctx context.Context, tableName string) (*TableSchema, error)

GetTableSchema returns the schema of a specific table

func (*MySQLDriver) GetTables

func (d *MySQLDriver) GetTables(ctx context.Context) ([]Table, error)

GetTables returns all tables in the database

func (*MySQLDriver) Ping

func (d *MySQLDriver) Ping(ctx context.Context) error

Ping tests the connection

func (*MySQLDriver) Query

func (d *MySQLDriver) Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

Query executes a query and returns rows

type PostgresDriver

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

PostgresDriver implements Driver interface for PostgreSQL

func NewPostgresDriver

func NewPostgresDriver(cfg *config.DatabaseConfig) (*PostgresDriver, error)

NewPostgresDriver creates a new PostgreSQL driver

func (*PostgresDriver) BeginTx

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

BeginTx starts a new transaction

func (*PostgresDriver) BulkInsert

func (d *PostgresDriver) BulkInsert(ctx context.Context, tableName string, columns []string, rows [][]interface{}) error

BulkInsert performs bulk insert operation

func (*PostgresDriver) Close

func (d *PostgresDriver) Close() error

Close closes the database connection

func (*PostgresDriver) Connect

func (d *PostgresDriver) Connect(ctx context.Context) error

Connect establishes a connection to PostgreSQL

func (*PostgresDriver) DatabaseName

func (d *PostgresDriver) DatabaseName() string

DatabaseName returns the database name

func (*PostgresDriver) DriverName

func (d *PostgresDriver) DriverName() string

DriverName returns the driver name

func (*PostgresDriver) Execute

func (d *PostgresDriver) Execute(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

Execute executes a query that doesn't return rows

func (*PostgresDriver) GetPrimaryKey

func (d *PostgresDriver) GetPrimaryKey(ctx context.Context, tableName string) ([]string, error)

GetPrimaryKey returns the primary key columns of a table

func (*PostgresDriver) GetTableSchema

func (d *PostgresDriver) GetTableSchema(ctx context.Context, tableName string) (*TableSchema, error)

GetTableSchema returns the schema of a specific table

func (*PostgresDriver) GetTables

func (d *PostgresDriver) GetTables(ctx context.Context) ([]Table, error)

GetTables returns all tables in the database

func (*PostgresDriver) Ping

func (d *PostgresDriver) Ping(ctx context.Context) error

Ping tests the connection

func (*PostgresDriver) Query

func (d *PostgresDriver) Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

Query executes a query and returns rows

type Table

type Table struct {
	Name    string
	Schema  string
	Type    string // TABLE, VIEW, etc.
	Comment string
}

Table represents a database table

type TableSchema

type TableSchema struct {
	Name        string
	Columns     []Column
	PrimaryKey  []string
	Indexes     []Index
	ForeignKeys []ForeignKey
}

TableSchema represents the schema of a table

Jump to

Keyboard shortcuts

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