Documentation ¶
Index ¶
- Constants
- Variables
- func ConstructInsertQuery(ctx context.Context, dialectStr string, req InsertBuilderRequest) (string, []interface{}, error)
- func ConstructSelectByIDQuery(ctx context.Context, dialectStr string, req SelectByIDBuilderRequest) (string, []interface{}, error)
- func ConstructUpdateQuery(ctx context.Context, dialectStr string, req UpdateBuilderRequest) (string, []interface{}, error)
- func ConstructUpsertQuery(ctx context.Context, req ConstructUpsertQueryRequest) (string, []interface{}, error)
- func GetTestDatabaseNameForService(serviceName string) string
- func NewSqlConnection(ctx context.Context, o Options) (*sql.DB, error)
- func PrettyPrint(i interface{}) string
- func SqlRowsToUUIDs(ctx context.Context, rows *sql.Rows) ([]scalars.ID, error)
- func StringsToInterfaces(strs []string) []interface{}
- func UUIDsToInterfaces(ids []scalars.ID) []interface{}
- type Connection
- func (c *Connection) Begin(ctx context.Context) error
- func (c *Connection) Close(ctx context.Context) error
- func (c *Connection) Commit(ctx context.Context) error
- func (c Connection) ExecuteQuery(ctx context.Context, query string, args ...interface{}) (int64, error)
- func (c Connection) GetQueryableConnection(ctx context.Context) (QueryableConnection, error)
- func (c *Connection) IsInTransaction(ctx context.Context) bool
- func (c *Connection) MustClose(ctx context.Context)
- func (c *Connection) MustCommit(ctx context.Context)
- func (c *Connection) MustRollback(ctx context.Context)
- func (c Connection) QueryRow(ctx context.Context, v interface{}, query string, args ...interface{}) error
- func (c Connection) QueryRows(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (c *Connection) Rollback(ctx context.Context) error
- type ConnectionProvider
- type ConstructUpsertQueryRequest
- type InsertBuilderRequest
- type InsertTypeParams
- type ListTypeByIDsParams
- type Options
- type QueryableConnection
- type SelectByIDBuilderRequest
- type SelectOrderBy
- type SelectQueryBuilder
- type ServerOptions
- type UniqueIDsQueryBuilderParams
- type UpdateBuilderRequest
- type With
Constants ¶
const DEFAULT_POSTGRES_PORT int = 5432
const SQL_DIALECT = "postgres"
Variables ¶
var ErrDatabaseAlreadyInitialized = fmt.Errorf("Database connection is already initialized")
Functions ¶
func ConstructInsertQuery ¶
func ConstructSelectByIDQuery ¶
func ConstructSelectByIDQuery(ctx context.Context, dialectStr string, req SelectByIDBuilderRequest) (string, []interface{}, error)
ConstructSelectQuery creates a string SQL query with args
func ConstructUpdateQuery ¶
func ConstructUpdateQuery(ctx context.Context, dialectStr string, req UpdateBuilderRequest) (string, []interface{}, error)
ConstructSelectQuery creates a string SQL query with args
func ConstructUpsertQuery ¶
func ConstructUpsertQuery(ctx context.Context, req ConstructUpsertQueryRequest) (string, []interface{}, error)
func PrettyPrint ¶
func PrettyPrint(i interface{}) string
func SqlRowsToUUIDs ¶
func StringsToInterfaces ¶
func StringsToInterfaces(strs []string) []interface{}
func UUIDsToInterfaces ¶
Types ¶
type Connection ¶
func NewMockConnection ¶
func NewMockConnection(ctx context.Context, serviceName string) (*Connection, error)
func (Connection) ExecuteQuery ¶
func (c Connection) ExecuteQuery(ctx context.Context, query string, args ...interface{}) (int64, error)
ExecuteQuery executes an insert or update query, returning the number of rows affected.
func (Connection) GetQueryableConnection ¶
func (c Connection) GetQueryableConnection(ctx context.Context) (QueryableConnection, error)
GetSQLConnection returns a direct sql.DB or sql.Tx object that can be used to run queries
func (*Connection) IsInTransaction ¶
func (c *Connection) IsInTransaction(ctx context.Context) bool
func (*Connection) MustClose ¶
func (c *Connection) MustClose(ctx context.Context)
MustClose is usefull for defer function calls where we can't easily handle err returns
func (*Connection) MustCommit ¶
func (c *Connection) MustCommit(ctx context.Context)
func (*Connection) MustRollback ¶
func (c *Connection) MustRollback(ctx context.Context)
func (Connection) QueryRow ¶
func (c Connection) QueryRow(ctx context.Context, v interface{}, query string, args ...interface{}) error
type ConnectionProvider ¶
type ConnectionProvider struct { Dialect string DbName string // DB *sql.DB // Tx *sql.Tx // NumTxs int // UseTransaction bool // Do we need this extra bool? InitOptions Options // Options used to initialize the connection }
Connection (DB Connection) is a struct that will hold database connection details
func GetExistingConnectionProviderByDatabase ¶
func GetExistingConnectionProviderByDatabase(ctx context.Context, dbname string) (*ConnectionProvider, error)
func NewConnectionProvider ¶
func NewConnectionProvider(ctx context.Context, opt Options) (ConnectionProvider, error)
NewConnectionProvider initializes a totally new database connection provider. It does not check if the connection is already initialized. This should ideally not be used directly, but through NewOrExistingConnectionProvider (which reuses existing providers).
func NewOrExistingConnectionProvider ¶
func NewOrExistingConnectionProvider(ctx context.Context, o Options) (*ConnectionProvider, error)
NewOrExistingConnectionProvider initializes a new database connection, and also saves it in the global map of connections.
func (*ConnectionProvider) GetConnection ¶
func (c *ConnectionProvider) GetConnection(ctx context.Context) (*Connection, error)
type InsertBuilderRequest ¶
type InsertTypeParams ¶
type InsertTypeParams struct {
TableName string
}
type ListTypeByIDsParams ¶
type Options ¶
type Options struct { Database string ServerOptions }
type QueryableConnection ¶
type QueryableConnection interface { ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row }
QueryableConnection groups together a sql.Connection, sq.DB (with pool handling) and a Transaction
type SelectOrderBy ¶
type SelectQueryBuilder ¶
type SelectQueryBuilder struct { Withs []With Select *goqu.SelectDataset }
func (SelectQueryBuilder) ToGoquDataset ¶
func (b SelectQueryBuilder) ToGoquDataset() *goqu.SelectDataset
func (SelectQueryBuilder) ToSQL ¶
func (b SelectQueryBuilder) ToSQL() (string, []interface{}, error)
type ServerOptions ¶
ServerOptions are the options required to initialize a connection for a service. The database name is not required since it's the same as the service name. This is used for the generated service code to initialize the database connection for a service.