Documentation
¶
Index ¶
- Variables
- type Column
- type Driver
- type ForeignKey
- type Index
- type MySQLDriver
- func (d *MySQLDriver) BeginTx(ctx context.Context) (*sql.Tx, error)
- func (d *MySQLDriver) BulkInsert(ctx context.Context, tableName string, columns []string, rows [][]interface{}) error
- func (d *MySQLDriver) Close() error
- func (d *MySQLDriver) Connect(ctx context.Context) error
- func (d *MySQLDriver) DatabaseName() string
- func (d *MySQLDriver) DriverName() string
- func (d *MySQLDriver) Execute(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (d *MySQLDriver) GetPrimaryKey(ctx context.Context, tableName string) ([]string, error)
- func (d *MySQLDriver) GetTableSchema(ctx context.Context, tableName string) (*TableSchema, error)
- func (d *MySQLDriver) GetTables(ctx context.Context) ([]Table, error)
- func (d *MySQLDriver) Ping(ctx context.Context) error
- func (d *MySQLDriver) Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- type PostgresDriver
- func (d *PostgresDriver) BeginTx(ctx context.Context) (*sql.Tx, error)
- func (d *PostgresDriver) BulkInsert(ctx context.Context, tableName string, columns []string, rows [][]interface{}) error
- func (d *PostgresDriver) Close() error
- func (d *PostgresDriver) Connect(ctx context.Context) error
- func (d *PostgresDriver) DatabaseName() string
- func (d *PostgresDriver) DriverName() string
- func (d *PostgresDriver) Execute(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (d *PostgresDriver) GetPrimaryKey(ctx context.Context, tableName string) ([]string, error)
- func (d *PostgresDriver) GetTableSchema(ctx context.Context, tableName string) (*TableSchema, error)
- func (d *PostgresDriver) GetTables(ctx context.Context) ([]Table, error)
- func (d *PostgresDriver) Ping(ctx context.Context) error
- func (d *PostgresDriver) Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- type Table
- type TableSchema
Constants ¶
This section is empty.
Variables ¶
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
type ForeignKey ¶
type ForeignKey struct {
Name string
Columns []string
ReferencedTable string
ReferencedColumns []string
OnUpdate string
OnDelete string
}
ForeignKey represents a foreign key constraint
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) 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 ¶
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
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) 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 ¶
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
type TableSchema ¶
type TableSchema struct {
Name string
Columns []Column
PrimaryKey []string
Indexes []Index
ForeignKeys []ForeignKey
}
TableSchema represents the schema of a table