db

package
v0.0.0-...-3b37697 Latest Latest
Warning

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

Go to latest
Published: May 4, 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 ColumnSchema

type ColumnSchema struct {
	Name      string
	Type      string
	IsID      bool // True if this is an ID column
	Nullable  bool
	MaxLength int // Maximum length for varchar fields
}

ColumnSchema represents the structure of a table column

type Connection

type Connection struct {
	Type DBType
	// contains filtered or unexported fields
}

Connection represents a database connection

func Connect

func Connect(dbURL string, cfg *config.Config, maxOpenConns int) (*Connection, error)

Connect establishes a database connection from a URL string

func (*Connection) Close

func (c *Connection) Close() error

Close closes the database connection

func (*Connection) DeleteBatch

func (c *Connection) DeleteBatch(table string, idCol string, ids []interface{}) error

DeleteBatch deletes rows from the given table where id is between minID and maxID and not in the provided ids. ids must be a pre-sorted, non-empty slice of interface{} representing the IDs to keep.

func (*Connection) DeleteBatchWithCount

func (c *Connection) DeleteBatchWithCount(table string, idCol string, ids []interface{}) (int64, error)

DeleteBatchWithCount deletes rows from the given table where id is between minID and maxID and not in the provided ids. Returns the number of rows deleted and any error that occurred. ids must be a pre-sorted, non-empty slice of interface{} representing the IDs to keep.

func (*Connection) DisableForeignKeyChecks

func (c *Connection) DisableForeignKeyChecks(db *sql.Tx) error

DisableForeignKeyChecks disables foreign key constraint checking

func (*Connection) EnableForeignKeyChecks

func (c *Connection) EnableForeignKeyChecks() error

EnableForeignKeyChecks enables foreign key constraint checking

func (*Connection) GetDB

func (c *Connection) GetDB() *sql.DB

GetDB returns the underlying *sql.DB instance

func (*Connection) GetSchema

func (c *Connection) GetSchema() ([]TableSchema, error)

GetSchema retrieves the database schema for all tables

func (*Connection) UpsertRow

func (c *Connection) UpsertRow(schema *TableSchema, data map[string]interface{}) error

UpsertRow handles inserting or updating a row in the destination database

type DBType

type DBType string
const (
	MySQL      DBType = "mysql"
	PostgreSQL DBType = "postgres"
)

type TableSchema

type TableSchema struct {
	Name    string
	Columns []ColumnSchema
	HasID   bool   // Indicates if table has an ID field for upsert logic
	IDCol   string // Name of the ID column, if any
}

TableSchema represents the structure of a database table

Jump to

Keyboard shortcuts

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