Documentation
¶
Index ¶
- func CleanStressTest()
- func ContextWithDbConn(parent context.Context, db *Database, conn *DbConn) context.Context
- func DeletePolicy(ctx context.Context, table string, name string) error
- func DeletePrivilege(ctx context.Context, privilege *Privilege) error
- func DeleteRole(ctx context.Context, name string) error
- func DeleteSchema(ctx context.Context, name string, cascade bool) error
- func DeleteUser(ctx context.Context, name string) error
- func FillContext(ctx context.Context, r *http.Request, db *Database, conn *DbConn, role string) context.Context
- func HasTX(c *DbPoolConn) bool
- func PrepareConnection(ctx context.Context, conn *DbPoolConn, role string, claims string, ...) error
- func PrepareStressTest(conn *pgxpool.Conn)
- func ReleaseConn(ctx context.Context, conn *DbPoolConn) error
- func ReleaseConnection(ctx context.Context, conn *DbPoolConn, err bool, resetRole bool) error
- func SetQueryBuilder(ctx context.Context, qb QueryBuilder)
- func SetRequestParser(ctx context.Context, rp RequestParser)
- func StressTest()
- type Argument
- type BuildError
- type BuildStack
- type Column
- type ColumnType
- type ColumnUpdate
- type CommonBuilder
- func (CommonBuilder) BuildDelete(table string, parts *QueryParts, options QueryOptions, info *SchemaInfo) (delete string, valueList []any, err error)
- func (CommonBuilder) BuildExecute(name string, record Record, parts *QueryParts, options QueryOptions, ...) (exec string, valueList []any, err error)
- func (CommonBuilder) BuildInsert(table string, records []Record, parts *QueryParts, options QueryOptions, ...) (insert string, valueList []any, err error)
- func (CommonBuilder) BuildUpdate(table string, record Record, parts *QueryParts, options QueryOptions, ...) (update string, valueList []any, err error)
- type Config
- type Constraint
- type Database
- func (db *Database) AcquireConnection(ctx context.Context) (*pgxpool.Conn, error)
- func (db *Database) Activate(ctx context.Context) error
- func (db *Database) Close()
- func (db *Database) CreateColumn(ctx context.Context, column *Column) (*Column, error)
- func (db *Database) CreateConstraint(ctx context.Context, constraint *Constraint) (*Constraint, error)
- func (db *Database) CreateFunction(ctx context.Context, function *Function) (*Function, error)
- func (db *Database) CreateRecords(ctx context.Context, table string, records []Record, filters Filters) ([]byte, int64, error)
- func (db *Database) CreateTable(ctx context.Context, table *Table) (*Table, error)
- func (db *Database) CreateView(ctx context.Context, view *View) (*View, error)
- func (db *Database) DeleteColumn(ctx context.Context, table string, name string, cascade bool) error
- func (db *Database) DeleteConstraint(ctx context.Context, table string, name string) error
- func (db *Database) DeleteFunction(ctx context.Context, name string) error
- func (db *Database) DeleteRecords(ctx context.Context, table string, filters Filters) ([]byte, int64, error)
- func (db *Database) DeleteTable(ctx context.Context, name string) error
- func (db *Database) DeleteView(ctx context.Context, name string) error
- func (db *Database) ExecFunction(ctx context.Context, name string, record Record, filters Filters) ([]byte, int64, error)
- func (db *Database) GetColumn(ctx context.Context, ftablename string, name string) (*Column, error)
- func (db *Database) GetColumnTypes(ctx context.Context) ([]ColumnType, error)
- func (db *Database) GetColumns(ctx context.Context, ftablename string) ([]Column, error)
- func (db *Database) GetConstraints(ctx context.Context, tablename string) ([]Constraint, error)
- func (db *Database) GetFunctions(ctx context.Context) ([]Function, error)
- func (db *Database) GetRecords(ctx context.Context, table string, filters Filters) ([]byte, error)
- func (db *Database) GetStructures(ctx context.Context, query string) ([]any, error)
- func (db *Database) GetTable(ctx context.Context, name string) (*Table, error)
- func (db *Database) GetTables(ctx context.Context) ([]Table, error)
- func (db *Database) GetView(ctx context.Context, name string) (*View, error)
- func (db *Database) GetViews(ctx context.Context) ([]View, error)
- func (db *Database) UpdateColumn(ctx context.Context, column *ColumnUpdate) (*Column, error)
- func (db *Database) UpdateRecords(ctx context.Context, table string, record Record, filters Filters) ([]byte, int64, error)
- func (db *Database) UpdateTable(ctx context.Context, table *TableUpdate) (*Table, error)
- type DatabaseInfo
- type DatabaseJSONSerializer
- type DbConn
- type DbEngine
- func (dbe *DbEngine) AcquireConnection(ctx context.Context) (*pgxpool.Conn, error)
- func (dbe *DbEngine) Close()
- func (dbe *DbEngine) CreateActiveDatabase(ctx context.Context, name string) (*Database, error)
- func (dbe *DbEngine) CreateDatabase(ctx context.Context, name string) (*DatabaseInfo, error)
- func (dbe *DbEngine) DeleteDatabase(ctx context.Context, name string) error
- func (dbe *DbEngine) GetActiveDatabase(ctx context.Context, name string) (*Database, error)
- func (dbe *DbEngine) GetDatabase(ctx context.Context, name string) (*DatabaseInfo, error)
- func (dbe *DbEngine) GetDatabases(ctx context.Context) ([]DatabaseInfo, error)
- func (dbe *DbEngine) IsDatabaseAllowed(name string) bool
- type DbLogger
- type DbPoolConn
- type DirectJSONSerializer
- type DirectQueryBuilder
- type Field
- type Filters
- type ForeignKey
- type Function
- type Join
- type OrderField
- type ParseError
- type Policy
- type PostgRestParser
- type Privilege
- type QueryBuilder
- type QueryExecutor
- func (QueryExecutor) Delete(ctx context.Context, table string, filters Filters) ([]byte, int64, error)
- func (QueryExecutor) Execute(ctx context.Context, function string, record Record, filters Filters) ([]byte, int64, error)
- func (QueryExecutor) Insert(ctx context.Context, table string, records []Record, filters Filters) ([]byte, int64, error)
- func (QueryExecutor) Select(ctx context.Context, table string, filters Filters) ([]byte, error)
- func (QueryExecutor) Update(ctx context.Context, table string, record Record, filters Filters) ([]byte, int64, error)
- type QueryOptions
- type QueryParts
- type QueryWithJSON
- type Record
- type ReflectSerializer
- type RelType
- type Relationship
- type Request
- type RequestParser
- type ResultSerializer
- type Role
- type Schema
- type SchemaInfo
- func (si *SchemaInfo) FindRelationshipByCol(table, col string) *Relationship
- func (si *SchemaInfo) GetColumnType(table string, column string) *ColumnType
- func (si *SchemaInfo) GetForeignKeys(table string) []ForeignKey
- func (si *SchemaInfo) GetFunction(name string) *Function
- func (si *SchemaInfo) GetPrimaryKey(table string) *Constraint
- func (si *SchemaInfo) GetRelationships(table string) []Relationship
- func (si *SchemaInfo) GetTable(table string) *Table
- func (si *SchemaInfo) GetTypeById(id uint32) *Type
- type SelectField
- type SelectRelation
- type SerializeError
- type SmoothContext
- type Table
- type TableUpdate
- type Type
- type User
- type View
- type WhereConditionNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanStressTest ¶
func CleanStressTest()
func ContextWithDbConn ¶
func FillContext ¶
func HasTX ¶
func HasTX(c *DbPoolConn) bool
func PrepareConnection ¶
func PrepareConnection(ctx context.Context, conn *DbPoolConn, role string, claims string, newAcquire bool) error
PrepareConnection starts a transaction if the configuration requires it, i.e. if TransactionEnd is not equal to 'none'. If the role parameter is not empty, it binds the role to the connection.
func PrepareStressTest ¶
func ReleaseConn ¶
func ReleaseConn(ctx context.Context, conn *DbPoolConn) error
ReleaseConn releases a connection to the proper pool. It is a simplified version of ReleaseConnection
func ReleaseConnection ¶
ReleaseConnection releases a connection to the proper pool. It resets its role if requested and closes the transaction, based on the configuration.
func SetQueryBuilder ¶
func SetQueryBuilder(ctx context.Context, qb QueryBuilder)
func SetRequestParser ¶
func SetRequestParser(ctx context.Context, rp RequestParser)
func StressTest ¶
func StressTest()
Types ¶
type BuildError ¶
type BuildError struct {
// contains filtered or unexported fields
}
func (*BuildError) Error ¶
func (e *BuildError) Error() string
type BuildStack ¶
type BuildStack struct {
// contains filtered or unexported fields
}
BuildStack represents the context when navigating the AST produced by the parser
type ColumnType ¶
type ColumnUpdate ¶
type CommonBuilder ¶
type CommonBuilder struct{}
func (CommonBuilder) BuildDelete ¶
func (CommonBuilder) BuildDelete(table string, parts *QueryParts, options QueryOptions, info *SchemaInfo) ( delete string, valueList []any, err error)
func (CommonBuilder) BuildExecute ¶
func (CommonBuilder) BuildExecute(name string, record Record, parts *QueryParts, options QueryOptions, info *SchemaInfo) ( exec string, valueList []any, err error)
func (CommonBuilder) BuildInsert ¶
func (CommonBuilder) BuildInsert(table string, records []Record, parts *QueryParts, options QueryOptions, info *SchemaInfo) ( insert string, valueList []any, err error)
func (CommonBuilder) BuildUpdate ¶
func (CommonBuilder) BuildUpdate(table string, record Record, parts *QueryParts, options QueryOptions, info *SchemaInfo) ( update string, valueList []any, err error)
type Config ¶
type Config struct {
URL string `comment:"Database URL (default: postgres://localhost:5432)"`
MinPoolConnections int32 `comment:"Miminum connections per pool (default: 10)"`
MaxPoolConnections int32 `comment:"Maximum connections per pool (default: 100)"`
AuthRole string `comment:"Authorization role (default: auth)"`
AnonRole string `comment:"Anonymous role (default: anon)"`
AllowedDatabases []string `comment:"Allowed databases (default: [] for all)"`
SchemaSearchPath []string `comment:"Schema search path (default: [] for Postgres search path)"`
TransactionEnd string `comment:"How to end a tx: none, commit, rollback (default: none)"`
}
func DefaultConfig ¶
func DefaultConfig() *Config
type Constraint ¶
type Constraint struct {
Name string `json:"name"`
Type byte `json:"type"` // c: check, u: unique, p: primary, f: foreign
Table string `json:"table"`
Columns []string `json:"columns"`
RelatedTable *string `json:"reltable"`
RelatedColumns []string `json:"relcolumns"`
Definition string `json:"definition"`
}
type Database ¶
type Database struct {
DatabaseInfo
// contains filtered or unexported fields
}
func (*Database) AcquireConnection ¶
func (*Database) Activate ¶
Activate initializes a database and starts its connection pool. It signals a db as activated even if there is an error, which is managed in DBE
func (*Database) CreateColumn ¶
func (*Database) CreateConstraint ¶
func (db *Database) CreateConstraint(ctx context.Context, constraint *Constraint) (*Constraint, error)
func (*Database) CreateFunction ¶
func (*Database) CreateRecords ¶
func (*Database) CreateTable ¶
func (*Database) CreateView ¶
func (*Database) DeleteColumn ¶
func (*Database) DeleteConstraint ¶
func (*Database) DeleteFunction ¶
func (*Database) DeleteRecords ¶
func (*Database) DeleteTable ¶
func (*Database) DeleteView ¶
func (*Database) ExecFunction ¶
func (*Database) GetColumnTypes ¶
func (db *Database) GetColumnTypes(ctx context.Context) ([]ColumnType, error)
func (*Database) GetColumns ¶
func (*Database) GetConstraints ¶
func (*Database) GetFunctions ¶
func (*Database) GetRecords ¶
func (*Database) GetStructures ¶
/table?filter
func (*Database) UpdateColumn ¶
func (*Database) UpdateRecords ¶
func (*Database) UpdateTable ¶
type DatabaseInfo ¶
type DatabaseJSONSerializer ¶
type DatabaseJSONSerializer struct{}
func (DatabaseJSONSerializer) Serialize ¶
func (DatabaseJSONSerializer) Serialize(ctx context.Context, rows pgx.Rows, scalar bool, info *SchemaInfo) ([]byte, error)
func (DatabaseJSONSerializer) SerializeSingle ¶
func (DatabaseJSONSerializer) SerializeSingle(ctx context.Context, rows pgx.Rows, scalar bool, info *SchemaInfo) ([]byte, error)
type DbEngine ¶
type DbEngine struct {
// contains filtered or unexported fields
}
DbEngine represents the database engine (a "cluster")
var DBE *DbEngine
func InitDbEngine ¶
InitDbEngine creates a connection pool, connects to the engine and initializes it
func (*DbEngine) AcquireConnection ¶
AcquireConnection acquires a connection in the database engine
func (*DbEngine) Close ¶
func (dbe *DbEngine) Close()
Close closes the database engine and all of its active databases
func (*DbEngine) CreateActiveDatabase ¶
func (*DbEngine) CreateDatabase ¶
func (*DbEngine) DeleteDatabase ¶
func (*DbEngine) GetActiveDatabase ¶
func (*DbEngine) GetDatabase ¶
func (*DbEngine) GetDatabases ¶
func (dbe *DbEngine) GetDatabases(ctx context.Context) ([]DatabaseInfo, error)
func (*DbEngine) IsDatabaseAllowed ¶
IsDatabaseAllowed chacks if a database is usable
type DbLogger ¶
type DbLogger struct {
// contains filtered or unexported fields
}
func NewDbLogger ¶
NewDbLogger accepts a zerolog.Logger as input and returns a new custom pgx logging facade as output.
type DbPoolConn ¶
func AcquireConnection ¶
func AcquireConnection(ctx context.Context, db *Database) (conn *DbPoolConn, err error)
AcquireConnection takes a connection from a database pool. If the db parameter is nil, it uses the global engine pool.
func ContextWithDb ¶
type DirectJSONSerializer ¶
func (*DirectJSONSerializer) Serialize ¶
func (d *DirectJSONSerializer) Serialize(ctx context.Context, rows pgx.Rows, scalar bool, info *SchemaInfo) ([]byte, error)
func (*DirectJSONSerializer) SerializeSingle ¶
func (d *DirectJSONSerializer) SerializeSingle(ctx context.Context, rows pgx.Rows, scalar bool, info *SchemaInfo) ([]byte, error)
type DirectQueryBuilder ¶
type DirectQueryBuilder struct {
CommonBuilder
}
func (DirectQueryBuilder) BuildSelect ¶
func (DirectQueryBuilder) BuildSelect(table string, parts *QueryParts, options QueryOptions, info *SchemaInfo) (string, []any, error)
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field represents a column and its attributes in the different parts of a query: select, where, order, etc clauses
type ForeignKey ¶
type Function ¶
type Function struct {
Name string `json:"name"`
Arguments []Argument `json:"arguments"`
Returns string `json:"returns"`
Language string `json:"language"`
Definition string `json:"definition"`
ReturnTypeId uint32 `json:"rettypeid"`
ReturnIsSet bool `json:"retisset"`
HasUnnamed bool `json:"hasunnamed"` // has unnamed parameters
HasOut bool `json:"hasout"` // has OUT, INOUT, TABLE parameters
}
type Join ¶
type Join struct {
// contains filtered or unexported fields
}
Join containts information to create a join relationship. It is composed while building the select clause.
type OrderField ¶
type OrderField struct {
// contains filtered or unexported fields
}
type ParseError ¶
type ParseError struct {
// contains filtered or unexported fields
}
func (*ParseError) Error ¶
func (e *ParseError) Error() string
type Policy ¶
type PostgRestParser ¶
type PostgRestParser struct {
// contains filtered or unexported fields
}
type Privilege ¶
type Privilege struct {
TargetName string `json:"targetname"`
TargetSchema string `json:"targetschema,omitempty"`
TargetType string `json:"targettype"` // database, schema, table, column, function
Columns []string `json:"columns,omitempty"` // to insert column privileges
Types []string `json:"types"`
Grantee string `json:"grantee"`
Grantor string `json:"grantor"`
ACL string `json:"acl"`
}
func CreatePrivilege ¶
func GetDatabasePrivileges ¶
type QueryBuilder ¶
type QueryBuilder interface {
BuildSelect(table string, parts *QueryParts, options QueryOptions, info *SchemaInfo) (string, []any, error)
BuildInsert(table string, records []Record, parts *QueryParts, options QueryOptions, info *SchemaInfo) (string, []any, error)
BuildUpdate(table string, record Record, parts *QueryParts, options QueryOptions, info *SchemaInfo) (string, []any, error)
BuildDelete(table string, parts *QueryParts, options QueryOptions, info *SchemaInfo) (string, []any, error)
BuildExecute(table string, record Record, parts *QueryParts, options QueryOptions, info *SchemaInfo) (string, []any, error)
// contains filtered or unexported methods
}
type QueryExecutor ¶
type QueryExecutor struct{}
type QueryOptions ¶
type QueryParts ¶
type QueryParts struct {
// contains filtered or unexported fields
}
QueryParts is the root of the AST produced by the request parser
type QueryWithJSON ¶
type QueryWithJSON struct {
CommonBuilder
}
func (QueryWithJSON) BuildSelect ¶
func (QueryWithJSON) BuildSelect(table string, parts *QueryParts, options QueryOptions, info *SchemaInfo) (string, []any, error)
type ReflectSerializer ¶
type ReflectSerializer struct{}
type Relationship ¶
type RequestParser ¶
type RequestParser interface {
// contains filtered or unexported methods
}
RequestParser is the interface used to parse the query string in the request and extract the significant headers. Initially we will support PostgREST mode and later perhaps others (Django?).
type ResultSerializer ¶
type Role ¶
type Role struct {
Name string `json:"name"`
IsSuperUser bool `json:"issuperuser"`
CanLogin bool `json:"canlogin"`
NoInheritPrivileges bool `json:"noinherit"`
CanCreateRoles bool `json:"cancreateroles"`
CanCreateDatabases bool `json:"cancreatedatabases"`
CanBypassRLS bool `json:"canbypassrls"`
MemberOf []string `json:"memberof"` // readonly for now
}
type SchemaInfo ¶
type SchemaInfo struct {
// contains filtered or unexported fields
}
func NewSchemaInfo ¶
func NewSchemaInfo(ctx context.Context, db *Database) (*SchemaInfo, error)
func (*SchemaInfo) FindRelationshipByCol ¶
func (si *SchemaInfo) FindRelationshipByCol(table, col string) *Relationship
func (*SchemaInfo) GetColumnType ¶
func (si *SchemaInfo) GetColumnType(table string, column string) *ColumnType
func (*SchemaInfo) GetForeignKeys ¶
func (si *SchemaInfo) GetForeignKeys(table string) []ForeignKey
func (*SchemaInfo) GetFunction ¶
func (si *SchemaInfo) GetFunction(name string) *Function
func (*SchemaInfo) GetPrimaryKey ¶
func (si *SchemaInfo) GetPrimaryKey(table string) *Constraint
func (*SchemaInfo) GetRelationships ¶
func (si *SchemaInfo) GetRelationships(table string) []Relationship
func (*SchemaInfo) GetTable ¶
func (si *SchemaInfo) GetTable(table string) *Table
func (*SchemaInfo) GetTypeById ¶
func (si *SchemaInfo) GetTypeById(id uint32) *Type
type SelectField ¶
type SelectField struct {
// contains filtered or unexported fields
}
SelectField can contain a selected field or a relationship with another table. For example, select=id,name,other(name) will produce:
- a SelectField with field.name = "id"
- a SelectField with field.name = "name"
- a SelectField with an empty field and a SelectRelation with relation.name = "other", itself with a SelectField in relation.fields with field.name = "name".
label is used as an alias both for a field and a relation.
type SelectRelation ¶
type SelectRelation struct {
// contains filtered or unexported fields
}
SelectRelation stores information about a relationship, expressed in the select clause like: /table?select=id,name,other1(name),...other2(id)
type SerializeError ¶
type SerializeError struct {
// contains filtered or unexported fields
}
func (*SerializeError) Error ¶
func (e *SerializeError) Error() string
type SmoothContext ¶
type SmoothContext struct {
Db *Database
Conn *DbConn
Role string
RequestParser RequestParser
QueryBuilder QueryBuilder
QueryOptions QueryOptions
}
func GetSmoothContext ¶
func GetSmoothContext(ctx context.Context) *SmoothContext
type Table ¶
type Table struct {
Name string `json:"name"`
Owner string `json:"owner"`
RowSecurity bool `json:"rowsecurity"`
HasIndexes bool `json:"hasindexes"`
HasTriggers bool `json:"hastriggers"`
IsPartition bool `json:"ispartition"`
Constraints []string `json:"constraints"`
Columns []Column `json:"columns,omitempty"`
Inherits string `json:"inherit,omitempty"`
IfNotExists bool `json:"ifnotexists,omitempty"`
}
type TableUpdate ¶
type Type ¶
type Type struct {
Id uint32 `json:"id"`
Name string `json:"name"`
Schema string `json:"schema"`
IsArray bool `json:"isarray"`
IsRange bool `json:"isrange"`
IsComposite bool `json:"iscomposite"`
IsTable bool `json:"istable"`
IsEnum bool `json:"isenum"`
ArraySubType uint32 `json:"arraysubtype"`
RangeSubType *uint32 `json:"rangesubtype"`
SubTypeIds []uint32 `json:"subtypeids"`
SubTypeNames []string `json:"subtypenames"`
}
type WhereConditionNode ¶
type WhereConditionNode struct {
// contains filtered or unexported fields
}