Documentation ¶
Index ¶
- type ColumnType
- type DB
- func (d *DB) Close() error
- func (c *DB) CountTableRows(ctx context.Context, relation sqlconnect.RelationRef) (int, error)
- func (db *DB) CreateSchema(ctx context.Context, schema sqlconnect.SchemaRef) error
- func (db *DB) CreateTableFromQuery(ctx context.Context, table sqlconnect.RelationRef, query string) error
- func (db *DB) CreateTestTable(ctx context.Context, table sqlconnect.RelationRef) error
- func (db *DB) CurrentCatalog(ctx context.Context) (string, error)
- func (db *DB) DropSchema(ctx context.Context, schemaRef sqlconnect.SchemaRef) error
- func (db *DB) DropTable(ctx context.Context, ref sqlconnect.RelationRef) error
- func (db *DB) GetRowCountForQuery(ctx context.Context, query string, params ...any) (int, error)
- func (db *DB) JSONRowMapper() sqlconnect.RowMapper[map[string]any]
- func (db *DB) ListColumns(ctx context.Context, relation sqlconnect.RelationRef) ([]sqlconnect.ColumnRef, error)
- func (db *DB) ListColumnsForSqlQuery(ctx context.Context, sql string) ([]sqlconnect.ColumnRef, error)
- func (db *DB) ListSchemas(ctx context.Context) ([]sqlconnect.SchemaRef, error)
- func (db *DB) ListTables(ctx context.Context, schema sqlconnect.SchemaRef) ([]sqlconnect.RelationRef, error)
- func (db *DB) ListTablesWithPrefix(ctx context.Context, schema sqlconnect.SchemaRef, prefix string) ([]sqlconnect.RelationRef, error)
- func (db *DB) MoveTable(ctx context.Context, oldRef, newRef sqlconnect.RelationRef) error
- func (db *DB) RenameTable(ctx context.Context, oldRef, newRef sqlconnect.RelationRef) error
- func (db *DB) SchemaExists(ctx context.Context, schemaRef sqlconnect.SchemaRef) (bool, error)
- func (db *DB) SqlDB() *sql.DB
- func (db *DB) TableExists(ctx context.Context, relation sqlconnect.RelationRef) (bool, error)
- func (db *DB) TruncateTable(ctx context.Context, ref sqlconnect.RelationRef) error
- type Option
- func WithColumnTypeMapper(columnTypeMapper func(ColumnType) string) Option
- func WithColumnTypeMappings(columnTypeMappings map[string]string) Option
- func WithDialect(dialect sqlconnect.Dialect) Option
- func WithJsonRowMapper(jsonRowMapper func(string, any) any) Option
- func WithSQLCommandsOverride(override func(defaultCommands SQLCommands) SQLCommands) Option
- type QuotedIdentifier
- type SQLCommands
- type UnquotedIdentifier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ColumnType ¶
type DB ¶
type DB struct { *sql.DB sqlconnect.Dialect // contains filtered or unexported fields }
func (*DB) CountTableRows ¶
func (c *DB) CountTableRows(ctx context.Context, relation sqlconnect.RelationRef) (int, error)
CountTableRows returns the number of rows in the given table
func (*DB) CreateSchema ¶
CreateSchema creates a schema
func (*DB) CreateTableFromQuery ¶
func (db *DB) CreateTableFromQuery(ctx context.Context, table sqlconnect.RelationRef, query string) error
CreateTableFromQuery creates a table from the results of a query
func (*DB) CreateTestTable ¶
func (db *DB) CreateTestTable(ctx context.Context, table sqlconnect.RelationRef) error
CreateTestTable creates a test table
func (*DB) CurrentCatalog ¶ added in v1.1.0
CurrentCatalog returns the current catalog
func (*DB) DropSchema ¶
DropSchema drops a schema
func (*DB) DropTable ¶
func (db *DB) DropTable(ctx context.Context, ref sqlconnect.RelationRef) error
DropTable drops a table
func (*DB) GetRowCountForQuery ¶
GetRowCountForQuery returns the number of rows returned by the query
func (*DB) JSONRowMapper ¶
func (db *DB) JSONRowMapper() sqlconnect.RowMapper[map[string]any]
JSONRowMapper returns a row mapper that maps scanned rows to [map[string]any]
func (*DB) ListColumns ¶
func (db *DB) ListColumns(ctx context.Context, relation sqlconnect.RelationRef) ([]sqlconnect.ColumnRef, error)
ListColumns returns a list of columns for the given table
func (*DB) ListColumnsForSqlQuery ¶
func (db *DB) ListColumnsForSqlQuery(ctx context.Context, sql string) ([]sqlconnect.ColumnRef, error)
ListColumnsForSqlQuery returns a list of columns for the given sql query
func (*DB) ListSchemas ¶
ListSchemas returns a list of schemas
func (*DB) ListTables ¶
func (db *DB) ListTables(ctx context.Context, schema sqlconnect.SchemaRef) ([]sqlconnect.RelationRef, error)
ListTables returns a list of tables in the given schema
func (*DB) ListTablesWithPrefix ¶
func (db *DB) ListTablesWithPrefix(ctx context.Context, schema sqlconnect.SchemaRef, prefix string) ([]sqlconnect.RelationRef, error)
ListTablesWithPrefix returns a list of tables in the given schema that have the given prefix
func (*DB) MoveTable ¶
func (db *DB) MoveTable(ctx context.Context, oldRef, newRef sqlconnect.RelationRef) error
MoveTable copies the old table's contents to the new table and drops the old table. Returns [ErrDropOldTablePostCopy] if the old table could not be dropped after the copy.
func (*DB) RenameTable ¶
func (db *DB) RenameTable(ctx context.Context, oldRef, newRef sqlconnect.RelationRef) error
RenameTable renames a table
func (*DB) SchemaExists ¶
SchemaExists returns true if the schema exists
func (*DB) TableExists ¶
func (db *DB) TableExists(ctx context.Context, relation sqlconnect.RelationRef) (bool, error)
TableExists returns true if the table exists
func (*DB) TruncateTable ¶
func (db *DB) TruncateTable(ctx context.Context, ref sqlconnect.RelationRef) error
TruncateTable truncates a table
type Option ¶
type Option func(*DB)
func WithColumnTypeMapper ¶
func WithColumnTypeMapper(columnTypeMapper func(ColumnType) string) Option
WithColumnTypeMapper sets the column type mapper for the client
func WithColumnTypeMappings ¶
WithColumnTypeMappings sets the column type mappings for the client
func WithDialect ¶
func WithDialect(dialect sqlconnect.Dialect) Option
WithDialect sets the dialect for the client
func WithJsonRowMapper ¶
WithJsonRowMapper sets the json row mapper for the client
func WithSQLCommandsOverride ¶
func WithSQLCommandsOverride(override func(defaultCommands SQLCommands) SQLCommands) Option
WithSQLCommandsOverride allows for overriding some of the sql commands that the client uses
type QuotedIdentifier ¶
type QuotedIdentifier string // A quoted identifier is a string that is quoted, e.g. "my_table"
type SQLCommands ¶
type SQLCommands struct { // Provides the SQL command to get the current catalog CurrentCatalog func() string // Provides the SQL command to create a schema CreateSchema func(schema QuotedIdentifier) string // Provides the SQL command to list all schemas ListSchemas func() (sql, columnName string) // Provides the SQL command to check if a schema exists SchemaExists func(schema UnquotedIdentifier) string // Provides the SQL command to drop a schema DropSchema func(schema QuotedIdentifier) string // Provides the SQL command to create a test table CreateTestTable func(table QuotedIdentifier) string // Provides the SQL command(s) to list all tables in a schema along with the column name that contains the table name in the result set ListTables func(schema UnquotedIdentifier) (sqlAndColumnNamePairs []lo.Tuple2[string, string]) // Provides the SQL command(s) to list all tables in a schema with a prefix along with the column name that contains the table name in the result set ListTablesWithPrefix func(schema UnquotedIdentifier, prefix string) []lo.Tuple2[string, string] // Provides the SQL command to check if a table exists TableExists func(schema, table UnquotedIdentifier) string // Provides the SQL command to list all columns in a table along with the column names in the result set that point to the name and type ListColumns func(catalog, schema, table UnquotedIdentifier) (sql, nameCol, typeCol string) // Provides the SQL command to count the rows in a table CountTableRows func(table QuotedIdentifier) string // Provides the SQL command to drop a table DropTable func(table QuotedIdentifier) string // Provides the SQL command to truncate a table TruncateTable func(table QuotedIdentifier) string // Provides the SQL command to rename a table RenameTable func(schema, oldName, newName QuotedIdentifier) string // Provides the SQL command to move a table MoveTable func(schema, oldName, newName QuotedIdentifier) string }
type UnquotedIdentifier ¶
type UnquotedIdentifier string // An unquoted identifier is a string that is not quoted, e.g. my_table