dbconnector

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColumnInfo

type ColumnInfo struct {
	Name     string
	DataType string
	Nullable bool
}

ColumnInfo represents column metadata

type Config

type Config struct {
	Type     DBType
	Host     string
	Port     int
	User     string
	Password string
	Database string
	SSLMode  string
}

Config holds database connection configuration

func ParseConnectionString

func ParseConnectionString(connStr string, dbType DBType) (*Config, error)

ParseConnectionString parses a connection string into Config

type Connector

type Connector interface {
	Connect() error
	Close() error
	ListTables() ([]string, error)
	GetTableSchema(tableName string) ([]ColumnInfo, error)
	ReadTable(tableName string, limit int) (*sql.Rows, error)
	Query(query string) (*sql.Rows, error)
	CreateTable(tableName string, columns []ColumnInfo) error
	InsertRow(tableName string, columns []string, values []any) error
}

Connector interface for database operations

func NewConnector

func NewConnector(config Config) (Connector, error)

NewConnector creates a new database connector based on the type

type DBType

type DBType string

DBType represents the type of database

const (
	DBTypePostgres DBType = "postgres"
	DBTypeMySQL    DBType = "mysql"
	DBTypeDuckDB   DBType = "duckdb"
	DBTypeMongoDB  DBType = "mongodb"
	DBTypeDynamoDB DBType = "dynamodb"
)

type DuckDBConnector

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

DuckDBConnector implements the Connector interface for DuckDB

func NewDuckDBConnector

func NewDuckDBConnector(config Config) (*DuckDBConnector, error)

NewDuckDBConnector creates a new DuckDB connector

func (*DuckDBConnector) Close

func (d *DuckDBConnector) Close() error

Close closes the database connection

func (*DuckDBConnector) Connect

func (d *DuckDBConnector) Connect() error

Connect establishes a connection to DuckDB

func (*DuckDBConnector) CreateTable

func (d *DuckDBConnector) CreateTable(tableName string, columns []ColumnInfo) error

CreateTable creates a new table

func (*DuckDBConnector) GetTableSchema

func (d *DuckDBConnector) GetTableSchema(tableName string) ([]ColumnInfo, error)

GetTableSchema returns the schema for a table

func (*DuckDBConnector) InsertRow

func (d *DuckDBConnector) InsertRow(tableName string, columns []string, values []any) error

InsertRow inserts a row into a table

func (*DuckDBConnector) ListTables

func (d *DuckDBConnector) ListTables() ([]string, error)

ListTables lists all tables in the database

func (*DuckDBConnector) Query

func (d *DuckDBConnector) Query(query string) (*sql.Rows, error)

Query executes a custom query

func (*DuckDBConnector) ReadTable

func (d *DuckDBConnector) ReadTable(tableName string, limit int) (*sql.Rows, error)

ReadTable reads all rows from a table

type DynamoDBConfig added in v1.0.0

type DynamoDBConfig struct {
	Region    string
	TableName string
	Endpoint  string // Optional: for LocalStack or local DynamoDB
}

DynamoDBConfig holds DynamoDB-specific configuration

type DynamoDBConnector added in v1.0.0

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

DynamoDBConnector implements the Connector interface for DynamoDB

func NewDynamoDBConnector added in v1.0.0

func NewDynamoDBConnector(cfg DynamoDBConfig) (*DynamoDBConnector, error)

NewDynamoDBConnector creates a new DynamoDB connector

func (*DynamoDBConnector) Close added in v1.0.0

func (d *DynamoDBConnector) Close() error

Close closes the DynamoDB connection

func (*DynamoDBConnector) Connect added in v1.0.0

func (d *DynamoDBConnector) Connect() error

Connect establishes a connection to DynamoDB

func (*DynamoDBConnector) CreateTable added in v1.0.0

func (d *DynamoDBConnector) CreateTable(tableName string, columns []ColumnInfo) error

CreateTable creates a DynamoDB table

func (*DynamoDBConnector) GetTableSchema added in v1.0.0

func (d *DynamoDBConnector) GetTableSchema(tableName string) ([]ColumnInfo, error)

GetTableSchema returns the schema for a DynamoDB table (inferred from first item)

func (*DynamoDBConnector) InsertRow added in v1.0.0

func (d *DynamoDBConnector) InsertRow(tableName string, columns []string, values []any) error

InsertRow inserts an item into a DynamoDB table

func (*DynamoDBConnector) ListTables added in v1.0.0

func (d *DynamoDBConnector) ListTables() ([]string, error)

ListTables lists all tables in DynamoDB

func (*DynamoDBConnector) Query added in v1.0.0

func (d *DynamoDBConnector) Query(query string) (*sql.Rows, error)

Query executes a query (not directly supported in DynamoDB for arbitrary SQL)

func (*DynamoDBConnector) ReadItems added in v1.0.0

func (d *DynamoDBConnector) ReadItems(tableName string, limit int) ([]map[string]interface{}, error)

ReadItems reads items from a DynamoDB table and returns them as maps

func (*DynamoDBConnector) ReadTable added in v1.0.0

func (d *DynamoDBConnector) ReadTable(tableName string, limit int) (*sql.Rows, error)

ReadTable reads all items from a DynamoDB table

type MongoDBConnector

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

MongoDBConnector implements the Connector interface for MongoDB

func NewMongoDBConnector

func NewMongoDBConnector(config Config) (*MongoDBConnector, error)

NewMongoDBConnector creates a new MongoDB connector

func (*MongoDBConnector) Close

func (m *MongoDBConnector) Close() error

Close closes the MongoDB connection

func (*MongoDBConnector) Connect

func (m *MongoDBConnector) Connect() error

Connect establishes a connection to MongoDB

func (*MongoDBConnector) CreateTable

func (m *MongoDBConnector) CreateTable(tableName string, columns []ColumnInfo) error

CreateTable creates a collection (MongoDB creates collections automatically)

func (*MongoDBConnector) GetTableSchema

func (m *MongoDBConnector) GetTableSchema(tableName string) ([]ColumnInfo, error)

GetTableSchema returns the schema for a collection (inferred from first document)

func (*MongoDBConnector) InsertRow

func (m *MongoDBConnector) InsertRow(tableName string, columns []string, values []any) error

InsertRow inserts a document into a collection

func (*MongoDBConnector) ListTables

func (m *MongoDBConnector) ListTables() ([]string, error)

ListTables lists all collections in the database

func (*MongoDBConnector) Query

func (m *MongoDBConnector) Query(query string) (*sql.Rows, error)

Query executes a query (not directly supported in MongoDB)

func (*MongoDBConnector) ReadCollection

func (m *MongoDBConnector) ReadCollection(tableName string, limit int) ([]map[string]interface{}, error)

ReadCollection reads documents from a MongoDB collection and returns them as maps

func (*MongoDBConnector) ReadTable

func (m *MongoDBConnector) ReadTable(tableName string, limit int) (*sql.Rows, error)

ReadTable reads all documents from a collection

func (*MongoDBConnector) SetCollection

func (m *MongoDBConnector) SetCollection(collection string)

SetCollection sets the collection to work with

type MySQLConnector

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

MySQLConnector implements the Connector interface for MySQL

func NewMySQLConnector

func NewMySQLConnector(config Config) (*MySQLConnector, error)

NewMySQLConnector creates a new MySQL connector

func (*MySQLConnector) Close

func (m *MySQLConnector) Close() error

Close closes the database connection

func (*MySQLConnector) Connect

func (m *MySQLConnector) Connect() error

Connect establishes a connection to the MySQL database

func (*MySQLConnector) CreateTable

func (m *MySQLConnector) CreateTable(tableName string, columns []ColumnInfo) error

CreateTable creates a new table

func (*MySQLConnector) GetTableSchema

func (m *MySQLConnector) GetTableSchema(tableName string) ([]ColumnInfo, error)

GetTableSchema returns the schema for a table

func (*MySQLConnector) InsertRow

func (m *MySQLConnector) InsertRow(tableName string, columns []string, values []any) error

InsertRow inserts a row into a table

func (*MySQLConnector) ListTables

func (m *MySQLConnector) ListTables() ([]string, error)

ListTables lists all tables in the database

func (*MySQLConnector) Query

func (m *MySQLConnector) Query(query string) (*sql.Rows, error)

Query executes a custom query

func (*MySQLConnector) ReadTable

func (m *MySQLConnector) ReadTable(tableName string, limit int) (*sql.Rows, error)

ReadTable reads all rows from a table

type PostgresConnector

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

PostgresConnector implements the Connector interface for PostgreSQL

func NewPostgresConnector

func NewPostgresConnector(config Config) (*PostgresConnector, error)

NewPostgresConnector creates a new PostgreSQL connector

func (*PostgresConnector) Close

func (p *PostgresConnector) Close() error

Close closes the database connection

func (*PostgresConnector) Connect

func (p *PostgresConnector) Connect() error

Connect establishes a connection to the PostgreSQL database

func (*PostgresConnector) CreateTable

func (p *PostgresConnector) CreateTable(tableName string, columns []ColumnInfo) error

CreateTable creates a new table

func (*PostgresConnector) GetTableSchema

func (p *PostgresConnector) GetTableSchema(tableName string) ([]ColumnInfo, error)

GetTableSchema returns the schema for a table

func (*PostgresConnector) InsertRow

func (p *PostgresConnector) InsertRow(tableName string, columns []string, values []any) error

InsertRow inserts a row into a table

func (*PostgresConnector) ListTables

func (p *PostgresConnector) ListTables() ([]string, error)

ListTables lists all tables in the database

func (*PostgresConnector) Query

func (p *PostgresConnector) Query(query string) (*sql.Rows, error)

Query executes a custom query

func (*PostgresConnector) ReadTable

func (p *PostgresConnector) ReadTable(tableName string, limit int) (*sql.Rows, error)

ReadTable reads all rows from a table

Jump to

Keyboard shortcuts

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