db

package
v0.0.0-...-4b3f104 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DEFAULT_CACHE_TTL time.Duration = 24 * 60 * 60

DEFAULT_CACHE_TTL is the default TTL for new cache entries (24 hours)

Variables

This section is empty.

Functions

func ConnectToBigQuery

func ConnectToBigQuery(config BigQueryConfig) (*bigquery.Client, error)

func ConnectToPostgres

func ConnectToPostgres(config PostgresConnectionConfig) (*sql.DB, error)

ConnectToPostgres establishes a connection to a PostgreSQL database.

func DisconnectFromDatabase

func DisconnectFromDatabase(databaseType string, connection DatabaseConnection) error

func DisconnectFromPostgres

func DisconnectFromPostgres(db *sql.DB) error

DisconnectFromPostgres closes the connection to the PostgreSQL database.

func GetColumnInfoBySchemaByDatabase

func GetColumnInfoBySchemaByDatabase(
	databaseType string,
	connection DatabaseConnection,

	tables []Table,
) (interface{}, error)

func GetColumnsByTableBigQuery

func GetColumnsByTableBigQuery(client *bigquery.Client, schemaName, tableName string) ([]string, error)

func GetColumnsByTableByDatabase

func GetColumnsByTableByDatabase(
	ctx context.Context,
	databaseType string,
	connection DatabaseConnection,
	schemaName string,
	tableName string,
) ([]string, error)

func GetColumnsByTablePostgres

func GetColumnsByTablePostgres(db *sql.DB, schemaName, tableName string) ([]string, error)

GetColumnsByTablePostgres retrieves the columns for a given table from the PostgreSQL database.

func GetDatabaseCredentials

func GetDatabaseCredentials(databaseType, connectionString string) (interface{}, error)

func GetForeignKeysBigQuery

func GetForeignKeysBigQuery(connection *bigquery.Client, schemaName, tableName, primaryKey string) ([]string, error)

func GetForeignKeysByDatabase

func GetForeignKeysByDatabase(
	ctx context.Context,
	databaseType string,
	connection DatabaseConnection,
	schemaName string,
	tableName string,
	primaryKey string,
) ([]string, error)

func GetForeignKeysPostgres

func GetForeignKeysPostgres(db *sql.DB, schemaName, tableName, primaryKey string) ([]string, error)

GetForeignKeysPostgres retrieves the foreign keys for a given table from the PostgreSQL database.

func GetSchemaBigQuery

func GetSchemaBigQuery(client *bigquery.Client) ([]string, error)

func GetSchemaColumnInfoPostgres

func GetSchemaColumnInfoPostgres(db *sql.DB, tableNames []Table) ([]map[string]interface{}, error)

GetSchemaColumnInfoPostgres retrieves column information for a given schema from the PostgreSQL database.

func GetSchemasByDatabase

func GetSchemasByDatabase(databaseType string, connection DatabaseConnection) ([]string, error)

func GetSchemasPostgres

func GetSchemasPostgres(db *sql.DB) ([]string, error)

GetSchemasPostgres retrieves the list of schemas from the PostgreSQL database.

func MapQueries

func MapQueries(queries []string, targetConnection *CachedConnection) ([]map[string]interface{}, error)

Types

type BigQueryConfig

type BigQueryConfig struct {
	DatasetName string
	ProjectID   string
	Credentials map[string]interface{}
}

func FormatBigQueryConfig

func FormatBigQueryConfig(connectionString string) (BigQueryConfig, error)

type CachedConnection

type CachedConnection struct {
	DatabaseType string
	Pool         DatabaseConnection
	OrgID        interface{}
	TTL          time.Duration
	Cache        models.RedisMapable
}

CachedConnection represents a cached database connection

func NewCachedConnection

func NewCachedConnection(databaseType string, config interface{}, cacheConfig models.CacheCredentials) (*CachedConnection, error)

NewCachedConnection creates a new CachedConnection

func (*CachedConnection) Close

func (c *CachedConnection) Close() error

Close closes the database connection

func (*CachedConnection) Query

func (c *CachedConnection) Query(text string) (interface{}, error)

Query executes a query and caches the result

type ColumnInfo

type ColumnInfo struct {
	ColumnName  string
	DataTypeID  int
	DisplayName string
	FieldType   string
}

type DatabaseConnection

type DatabaseConnection interface{} // TODO: Define this type

func ConnectToDatabase

func ConnectToDatabase(databaseType string, config interface{}) (DatabaseConnection, error)

type Field

type Field struct {
	Name       string `json:"name"`
	DataTypeID int    `json:"dataTypeID"`
}

type PostgresConnectionConfig

type PostgresConnectionConfig struct {
	ConnectionString string
	SSL              *struct {
		RejectUnauthorized bool
		CA                 *string
		Key                *string
		Cert               *string
	}
}

func FormatPostgresConfig

func FormatPostgresConfig(connectionString string) (PostgresConnectionConfig, error)

type QueryResults

type QueryResults struct {
	Fields []Field                  `json:"fields"`
	Rows   []map[string]interface{} `json:"rows"`
}

func RunQueryBigQuery

func RunQueryBigQuery(client *bigquery.Client, sql string) (*QueryResults, error)

func RunQueryByDatabase

func RunQueryByDatabase(databaseType string, connection DatabaseConnection, query string) (*QueryResults, error)

func RunQueryPostgres

func RunQueryPostgres(db *sql.DB, query string) (*QueryResults, error)

RunQueryPostgres executes a SQL query on the PostgreSQL database.

type RedisCache

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

RedisCache is a wrapper around *redis.Client that implements the Mapable interface

func (*RedisCache) Get

func (c *RedisCache) Get(key string) (string, error)

Get retrieves a value from the Redis cache

func (*RedisCache) Set

func (c *RedisCache) Set(key string, value interface{}, expiration time.Duration) error

Set sets a value in the Redis cache

type Table

type Table struct {
	TableName  string
	SchemaName string
}

func GetTablesBySchemaBigQuery

func GetTablesBySchemaBigQuery(client *bigquery.Client, schemaNames []string) ([]Table, error)

func GetTablesBySchemaByDatabase

func GetTablesBySchemaByDatabase(
	databaseType string,
	connection DatabaseConnection,
	schemaName interface{},
) ([]Table, error)

func GetTablesBySchemaPostgres

func GetTablesBySchemaPostgres(db *sql.DB, schemaNames []string) ([]Table, error)

GetTablesBySchemaPostgres retrieves the tables for the given schemas from the PostgreSQL database.

type TableColumnInfo

type TableColumnInfo struct {
	TableName   string
	DisplayName string
	Columns     []ColumnInfo
}

func GetSchemaColumnInfoBigQuery

func GetSchemaColumnInfoBigQuery(
	connection *bigquery.Client,

	tableNames []Table,
) ([]TableColumnInfo, error)

Jump to

Keyboard shortcuts

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