database

package
v0.2.10 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const DEFAULT_ANON = "anon"
View Source
const (
	SMOOTHDB = "smoothdb"
)

Variables

This section is empty.

Functions

func CheckDatabase added in v0.2.3

func CheckDatabase(dbConfig *Config) (bool, error)

func CleanStressTest

func CleanStressTest()

func ContextWithDbConn

func ContextWithDbConn(parent context.Context, db *Database, conn *DbConn) context.Context

ContextWithDb creates a context using a specific connection

func CreateRecords added in v0.2.0

func CreateRecords(ctx context.Context, table string, records []Record, filters Filters) ([]byte, int64, error)

func Delete added in v0.2.0

func Delete(ctx context.Context, table string, filters Filters) ([]byte, int64, error)

func DeleteColumn added in v0.1.2

func DeleteColumn(ctx context.Context, tablename string, name string, cascade bool) error

func DeleteConstraint added in v0.1.2

func DeleteConstraint(ctx context.Context, tablename string, name string) error

func DeleteFunction added in v0.2.0

func DeleteFunction(ctx context.Context, name string) error

func DeletePolicy

func DeletePolicy(ctx context.Context, table string, name string) error

func DeletePrivilege

func DeletePrivilege(ctx context.Context, privilege *Privilege) error

func DeleteRecords added in v0.2.0

func DeleteRecords(ctx context.Context, table string, filters Filters) ([]byte, int64, error)

func DeleteRole

func DeleteRole(ctx context.Context, name string) error

func DeleteSchema

func DeleteSchema(ctx context.Context, name string, cascade bool) error

func DeleteTable added in v0.1.2

func DeleteTable(ctx context.Context, name string, ifExists bool) error

func DeleteUser

func DeleteUser(ctx context.Context, name string) error

func DeleteView added in v0.2.6

func DeleteView(ctx context.Context, name string) error

func ExecFunction added in v0.2.0

func ExecFunction(ctx context.Context, fname string, record Record, filters Filters, readonly bool) ([]byte, int64, error)

func Execute added in v0.2.0

func Execute(ctx context.Context, function string, record Record, filters Filters, readonly bool) ([]byte, int64, error)

func FillContext

func FillContext(ctx context.Context, r *http.Request, db *Database, conn *DbConn, role string) context.Context

FillContext compiles and inserts the information related to the database, cresting a new derived context

func GetDbRole added in v0.2.4

func GetDbRole(ctx context.Context) string

GetDbRole gets the role from the current context

func GetDynStructures added in v0.2.4

func GetDynStructures(ctx context.Context, query string) ([]any, error)

func GetMaps added in v0.2.0

func GetMaps(ctx context.Context, query string) ([]map[string]any, error)

/table?filter

func GetRecords added in v0.2.0

func GetRecords(ctx context.Context, table string, filters Filters) ([]byte, int64, error)

func HasTX

func HasTX(c *DbPoolConn) bool

func Insert added in v0.2.0

func Insert(ctx context.Context, table string, records []Record, filters Filters) ([]byte, int64, error)

func IsExist added in v0.2.3

func IsExist(err error) 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 TransactionMode is not equal to 'none'. If the role parameter is not empty, it binds the role to the connection.

func PrepareDatabase added in v0.2.3

func PrepareDatabase(adminURL string, dbConfig *Config) error

PrepareDatabase prepares the database for SmoothDb

func PrepareStressTest

func PrepareStressTest(conn *pgxpool.Conn)

func QueryExec added in v0.2.4

func QueryExec(ctx context.Context, query string, values ...any) error

func QueryStructure added in v0.2.4

func QueryStructure[T any](ctx context.Context, query string, values ...any) (*T, error)

func QueryStructures added in v0.2.4

func QueryStructures[T any](ctx context.Context, query string, values ...any) ([]T, error)

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

func ReleaseConnection(ctx context.Context, conn *DbPoolConn, httpErr bool, resetRole bool) error

ReleaseConnection releases a connection to the proper pool. It resets its role if requested and closes the transaction, based on the configuration.

func Select added in v0.2.0

func Select(ctx context.Context, table string, filters Filters) ([]byte, int64, error)

func SetQueryBuilder

func SetQueryBuilder(ctx context.Context, qb QueryBuilder)

SetQueryBuilder allows changing the query builder in the current context

func SetRequestParser

func SetRequestParser(ctx context.Context, rp RequestParser)

SetRequestParser allows changing the request parser in the current context

func StressTest

func StressTest()

func Update added in v0.2.0

func Update(ctx context.Context, table string, record Record, filters Filters) ([]byte, int64, error)

func UpdateColumn added in v0.1.2

func UpdateColumn(ctx context.Context, tablename string, name string, column *ColumnUpdate) error

func UpdateRecords added in v0.2.0

func UpdateRecords(ctx context.Context, table string, record Record, filters Filters) ([]byte, int64, error)

func UpdateRole added in v0.2.7

func UpdateRole(ctx context.Context, name string, role *RoleUpdate) error

func UpdateSchema added in v0.2.7

func UpdateSchema(ctx context.Context, name string, schema *SchemaUpdate) error

func UpdateTable added in v0.1.2

func UpdateTable(ctx context.Context, name string, table *TableUpdate) error

Types

type Argument

type Argument struct {
	Name string
	Type string
	Mode byte // i IN, o OUT, b INOUT, v VARIADIC, t TABLE

}

type BinarySerializer added in v0.2.6

type BinarySerializer struct {
	bytes.Buffer
}

func (*BinarySerializer) Serialize added in v0.2.6

func (b *BinarySerializer) Serialize(rows pgx.Rows, scalar bool, single bool, info *SchemaInfo) ([]byte, int64, error)

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 CSVSerializer added in v0.2.5

type CSVSerializer struct {
	TextBuilder
}

func (*CSVSerializer) Serialize added in v0.2.5

func (csv *CSVSerializer) Serialize(rows pgx.Rows, scalar bool, single bool, info *SchemaInfo) ([]byte, int64, error)

type Column

type Column struct {
	Name        string   `json:"name"`
	Type        string   `json:"type"`
	NotNull     bool     `json:"notnull"`
	Default     *string  `json:"default"`
	Constraints []string `json:"constraints"`
	Table       string   `json:"table,omitempty"`
	Schema      string   `json:"schema,omitempty"`
}

func CreateColumn added in v0.1.2

func CreateColumn(ctx context.Context, column *Column) (*Column, error)

func GetColumn added in v0.1.2

func GetColumn(ctx context.Context, tablename string, name string) (*Column, error)

func GetColumns added in v0.1.2

func GetColumns(ctx context.Context, tablename string) ([]Column, error)

type ColumnType

type ColumnType struct {
	Table       string `json:"table"`
	Schema      string `json:"schema"`
	Name        string `json:"name"`
	Type        string `json:"type"`
	DataType    string `json:"datatype"`
	IsArray     bool   `json:"isarray"`
	IsComposite bool   `json:"iscomposite"`
}

func GetColumnTypes added in v0.1.2

func GetColumnTypes(ctx context.Context) ([]ColumnType, error)

type ColumnUpdate

type ColumnUpdate struct {
	Name    *string `json:"name"`
	Type    *string `json:"type"`
	NotNull *bool   `json:"notnull"`
	Default *string `json:"default"`
}

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) (
	query 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"`
	MinPoolConnections int32    `comment:"Miminum connections per pool (default: 10)"`
	MaxPoolConnections int32    `comment:"Maximum connections per pool (default: 100)"`
	AnonRole           string   `comment:"Anonymous role (default: '' for no anon)"`
	AllowedDatabases   []string `comment:"Allowed databases (default: [] for all)"`
	SchemaSearchPath   []string `comment:"Schema search path (default: [] for Postgres search path)"`
	TransactionMode    string   `` /* 137-byte string literal not displayed */
}

func DefaultConfig

func DefaultConfig() *Config

type Constraint

type Constraint struct {
	Name           string   `json:"name"`
	Type           string   `json:"type"` // check, unique, primary, foreign
	Table          string   `json:"table"`
	Schema         string   `json:"schema"`
	Columns        []string `json:"columns"`
	RelatedTable   *string  `json:"reltable"`
	RelatedSchema  *string  `json:"relschema"`
	RelatedColumns []string `json:"relcolumns"`
	Definition     string   `json:"definition"`
}

func CreateConstraint added in v0.1.2

func CreateConstraint(ctx context.Context, constraint *Constraint) (*Constraint, error)

func GetConstraints added in v0.1.2

func GetConstraints(ctx context.Context, tablename string) ([]Constraint, error)

type ContentTypeError added in v0.2.5

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

func (ContentTypeError) Error added in v0.2.5

func (e ContentTypeError) Error() string

type CustomRows added in v0.2.0

type CustomRows struct {
	FieldDescriptions_ []pgconn.FieldDescription
	RawValues_         [][][]byte
	CurrentRow         int
}

CustomRows is used for testing, to be able to do more iterations on a single query result. This is not permitted by pgx.Rows.

func CopyRows added in v0.2.0

func CopyRows(rows pgx.Rows) (*CustomRows, error)

func (*CustomRows) Close added in v0.2.0

func (cr *CustomRows) Close()

func (*CustomRows) CommandTag added in v0.2.0

func (cr *CustomRows) CommandTag() pgconn.CommandTag

func (*CustomRows) Conn added in v0.2.0

func (cr *CustomRows) Conn() *pgx.Conn

func (*CustomRows) Err added in v0.2.0

func (cr *CustomRows) Err() error

func (*CustomRows) FieldDescriptions added in v0.2.0

func (cr *CustomRows) FieldDescriptions() []pgconn.FieldDescription

func (*CustomRows) Next added in v0.2.0

func (cr *CustomRows) Next() bool

func (*CustomRows) RawValues added in v0.2.0

func (cr *CustomRows) RawValues() [][]byte

func (*CustomRows) Scan added in v0.2.0

func (cr *CustomRows) Scan(dest ...any) error

func (*CustomRows) Values added in v0.2.0

func (cr *CustomRows) Values() ([]any, error)

type Database

type Database struct {
	DatabaseInfo
	// contains filtered or unexported fields
}

func GetDb

func GetDb(ctx context.Context) *Database

GetDb gets the database from the current context

func (*Database) AcquireConnection

func (db *Database) AcquireConnection(ctx context.Context) (*pgxpool.Conn, error)

func (*Database) Close

func (db *Database) Close()

type DatabaseInfo

type DatabaseInfo struct {
	Name  string `json:"name"`
	Owner string `json:"owner"`
}

type DatabaseJSONSerializer

type DatabaseJSONSerializer struct{}

func (DatabaseJSONSerializer) Serialize

func (DatabaseJSONSerializer) Serialize(rows pgx.Rows, scalar bool, single bool, info *SchemaInfo) ([]byte, int64, error)

type DatabaseUpdate added in v0.2.7

type DatabaseUpdate struct {
	Name  *string `json:"name"`
	Owner *string `json:"owner"`
}

type DbConn

type DbConn = pgx.Conn

func GetConn

func GetConn(ctx context.Context) *DbConn

GetConn gets the database connection from the current context

func GetConnAndSchema added in v0.2.7

func GetConnAndSchema(ctx context.Context) (*DbConn, string)

GetConnAndSchema gets the database connection and the schema from the current context

type DbEngine

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

DbEngine represents the database engine (the PostgreSQL instance or "cluster")

func InitDbEngine

func InitDbEngine(dbConfig *Config, logger *logging.Logger) (*DbEngine, error)

InitDbEngine creates a connection pool, connects to the engine and initializes it

func (*DbEngine) AcquireConnection

func (dbe *DbEngine) AcquireConnection(ctx context.Context) (*pgxpool.Conn, error)

AcquireConnection acquires a connection in the database engine

func (*DbEngine) CloneDatabase added in v0.2.3

func (dbe *DbEngine) CloneDatabase(ctx context.Context, name string, source string, force bool) (*DatabaseInfo, error)

CloneDatabase creates a new database cloning a source db. The force parameter can be used to stop all the connections to the source db, which is a prerequisite.

func (*DbEngine) Close

func (dbe *DbEngine) Close()

Close closes the database engine and all of its active databases

func (*DbEngine) CreateActiveDatabase

func (dbe *DbEngine) CreateActiveDatabase(ctx context.Context, name string, owner string) (*Database, error)

CreateActiveDatabase allows to create a database and ensures it is activated

func (*DbEngine) CreateDatabase

func (dbe *DbEngine) CreateDatabase(ctx context.Context, name string, owner string, getIfExists bool) (*DatabaseInfo, error)

CreateDatabase creates a new database Use CreateActiveDatabase to create an active instance of a database

func (*DbEngine) DeleteDatabase

func (dbe *DbEngine) DeleteDatabase(ctx context.Context, name string) error

DeleteDatabase deletes a database. It blocks until all connections are returned to pool.

func (*DbEngine) GetActiveDatabase

func (dbe *DbEngine) GetActiveDatabase(ctx context.Context, name string) (db *Database, err error)

GetActiveDatabase allows to get a database and ensures it is activated (eg it has a connection pool and its cached information)

func (*DbEngine) GetDatabase

func (dbe *DbEngine) GetDatabase(ctx context.Context, name string) (*DatabaseInfo, error)

GetDatabase gets information about a database. Use GetActiveDatabase to get an active instance of a database

func (*DbEngine) GetDatabases

func (dbe *DbEngine) GetDatabases(ctx context.Context) ([]DatabaseInfo, error)

GetDatabases lists the available databases, filtering the not-managed ones

func (*DbEngine) GetMainDatabase added in v0.2.4

func (dbe *DbEngine) GetMainDatabase(ctx context.Context) (*Database, error)

GetMainDatabase is used to get the main db

func (*DbEngine) GetOrCreateActiveDatabase added in v0.2.3

func (dbe *DbEngine) GetOrCreateActiveDatabase(ctx context.Context, name string) (*Database, error)

GetOrCreateActiveDatabase allows to get or create a database and ensures it is activated

func (*DbEngine) IsDatabaseAllowed

func (dbe *DbEngine) IsDatabaseAllowed(name string) bool

IsDatabaseAllowed checks if a database can be managed by smoothdb

func (*DbEngine) UpdateDatabase added in v0.2.7

func (dbe *DbEngine) UpdateDatabase(ctx context.Context, name string, update *DatabaseUpdate) error

UpdateDatabase updates a database.

type DbLogger

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

func NewDbLogger

func NewDbLogger(logger *zerolog.Logger) *DbLogger

NewDbLogger accepts a zerolog.Logger as input and returns a new custom pgx logging facade as output.

func (*DbLogger) Log

func (pl *DbLogger) Log(ctx context.Context, level tracelog.LogLevel, msg string, data map[string]interface{})

type DbPoolConn

type DbPoolConn = pgxpool.Conn

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 main db pool.

func ContextWithDb

func ContextWithDb(parent context.Context, db *Database, role string) (context.Context, *DbPoolConn, error)

ContextWithDb creates a context and gets a connection to the requested database, with a specific role. The db parameter can be nil, to indicate the main database. It is used to start a communication with a database, both internally and from code using smoothdb as a library.

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 Filters

type Filters = url.Values

type ForeignKey

type ForeignKey struct {
	Name           string
	Table          string
	Schema         string
	Columns        []string
	RelatedTable   string
	RelatedSchema  string
	RelatedColumns []string
}

type Function

type Function struct {
	Name         string     `json:"name"`
	Schema       string     `json:"schema"`
	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
	IsVariadic   bool       `json:"isvariadic"`
}

func CreateFunction added in v0.2.0

func CreateFunction(ctx context.Context, function *Function) (*Function, error)

func GetFunctions added in v0.2.5

func GetFunctions(ctx context.Context) ([]Function, error)

type JSONSerializer added in v0.2.5

type JSONSerializer struct {
	TextBuilder
}

func (*JSONSerializer) Serialize added in v0.2.5

func (j *JSONSerializer) Serialize(rows pgx.Rows, scalar bool, single bool, info *SchemaInfo) ([]byte, int64, error)

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 Policy struct {
	Name       string   `json:"name"`
	Table      string   `json:"table"`
	Retrictive bool     `json:"deny"`
	Command    string   `json:"command"`
	Roles      []string `json:"roles"`
	Using      *string  `json:"using"`
	Check      *string  `json:"check"`
}

func CreatePolicy

func CreatePolicy(ctx context.Context, policy *Policy) (*Policy, error)

func GetPolicies

func GetPolicies(ctx context.Context, ftablename string) ([]Policy, error)

type PostgRestParser

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

type PostgresConfig added in v0.2.3

type PostgresConfig struct {
	Host     string // host (e.g. localhost) or absolute path to unix domain socket directory (e.g. /private/tmp)
	Port     uint16
	Database string
	User     string
	Password string
}

func ParsePostgresURL added in v0.2.3

func ParsePostgresURL(url string) (*PostgresConfig, error)

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 CreatePrivilege(ctx context.Context, privilege *Privilege) (*Privilege, error)

func GetDatabasePrivileges

func GetDatabasePrivileges(ctx context.Context, dbname string) ([]Privilege, error)

func GetPrivileges

func GetPrivileges(ctx context.Context, targetType string, targetName string) ([]Privilege, error)

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 QueryOptions

type QueryOptions struct {
	Schema               string
	ContentType          string // json, csv
	ReturnRepresentation bool
	MergeDuplicates      bool
	IgnoreDuplicates     bool
	ParamsAsSingleObject bool
	TxCommit             bool
	TxRollback           bool
	Singular             bool
	HasRange             bool
	RangeMin             int64
	RangeMax             int64
	Count                string // exact, planned, estimated
}

func GetQueryOptions added in v0.2.7

func GetQueryOptions(ctx context.Context) *QueryOptions

GetQueryOptions gets the query options from the current context

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 RangeError added in v0.2.4

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

func (RangeError) Error added in v0.2.4

func (e RangeError) Error() string

type Record

type Record = map[string]any

type RelType

type RelType int
const (
	O2M RelType = iota
	M2O
	O2O
	M2M
)

type Relationship

type Relationship struct {
	Type            RelType
	Table           string
	Columns         []string
	RelatedTable    string
	RelatedColumns  []string
	JunctionTable   string
	JColumns        []string
	JRelatedColumns []string
}

type Request

type Request = http.Request

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 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
}

func CreateRole

func CreateRole(ctx context.Context, role *Role) (*Role, error)

func GetRole

func GetRole(ctx context.Context, name string) (*Role, error)

func GetRoles

func GetRoles(ctx context.Context) ([]Role, error)

type RoleUpdate added in v0.2.7

type RoleUpdate 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"`
}

type Schema

type Schema struct {
	Name  string `json:"name"`
	Owner string `json:"owner"`
}

func CreateSchema

func CreateSchema(ctx context.Context, schema *Schema) (*Schema, error)

func GetSchema added in v0.2.7

func GetSchema(ctx context.Context, name string) (*Schema, error)

func GetSchemas

func GetSchemas(ctx context.Context) ([]Schema, error)

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(ftable, col string) *Relationship

func (*SchemaInfo) GetColumnType

func (si *SchemaInfo) GetColumnType(ftable string, column string) *ColumnType

func (*SchemaInfo) GetForeignKeys

func (si *SchemaInfo) GetForeignKeys(ftable string) []ForeignKey

func (*SchemaInfo) GetFunction

func (si *SchemaInfo) GetFunction(name string) *Function

func (*SchemaInfo) GetPrimaryKey

func (si *SchemaInfo) GetPrimaryKey(ftable string) *Constraint

func (*SchemaInfo) GetRelationships

func (si *SchemaInfo) GetRelationships(ftable string) []Relationship

func (*SchemaInfo) GetTable

func (si *SchemaInfo) GetTable(ftable string) *Table

func (*SchemaInfo) GetTypeById

func (si *SchemaInfo) GetTypeById(id uint32) *Type

type SchemaUpdate added in v0.2.7

type SchemaUpdate struct {
	Name  *string `json:"name"`
	Owner *string `json:"owner"`
}

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:

  1. a SelectField with field.name = "id"
  2. a SelectField with field.name = "name"
  3. 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
}

SmoothContext contains all the information needed to perform database commands as well as configured parser and query builder

func GetSmoothContext

func GetSmoothContext(ctx context.Context) *SmoothContext

GetSmoothContext gets SmoothContext from the standard context

type Table

type Table struct {
	Name        string   `json:"name"`
	Schema      string   `json:"schema"`
	Owner       string   `json:"owner"`
	RowSecurity bool     `json:"rowsecurity"`
	Columns     []Column `json:"columns,omitempty"`
	Constraints []string `json:"constraints"`
	Inherits    string   `json:"inherit,omitempty"`
	IfNotExists bool     `json:"ifnotexists,omitempty"`
	HasIndexes  bool     `json:"hasindexes"`
	HasTriggers bool     `json:"hastriggers"`
	IsPartition bool     `json:"ispartition"`
}

func CreateTable added in v0.1.2

func CreateTable(ctx context.Context, table *Table) (*Table, error)

func GetTable added in v0.1.2

func GetTable(ctx context.Context, name string) (*Table, error)

func GetTables added in v0.1.2

func GetTables(ctx context.Context) ([]Table, error)

type TableUpdate

type TableUpdate struct {
	Name        *string `json:"name"`
	Schema      *string `json:"schema"`
	Owner       *string `json:"owner"`
	RowSecurity *bool   `json:"rowsecurity"`
}

type TextBuilder added in v0.2.5

type TextBuilder struct {
	strings.Builder
	// contains filtered or unexported fields
}

type TextSerializer added in v0.2.5

type TextSerializer interface {
	Serialize(rows pgx.Rows, scalar bool, single bool, info *SchemaInfo) ([]byte, int64, error)
}

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"`
	IsDomain      bool     `json:"isdomain"`
	ArraySubType  uint32   `json:"arraysubtype"`
	RangeSubType  *uint32  `json:"rangesubtype"`
	DomainSubType string   `json:"domainsubtype"`
	SubTypeIds    []uint32 `json:"subtypeids"`
	SubTypeNames  []string `json:"subtypenames"`
}

func GetTypes

func GetTypes(ctx context.Context) ([]Type, error)

type User

type User struct {
	Name               string   `json:"name"`
	MemberOf           []string `json:"memberof"`
	CanCreateRoles     bool     `json:"cancreateroles"`
	CanCreateDatabases bool     `json:"cancreatedatabases"`
}

func CreateUser

func CreateUser(ctx context.Context, user *User) (*User, error)

func GetUser

func GetUser(ctx context.Context, name string) (*User, error)

func GetUsers

func GetUsers(ctx context.Context) ([]User, error)

type View

type View struct {
	Name         string `json:"name"`
	Schema       string `json:"schema"`
	Owner        string `json:"owner"`
	Definition   string `json:"definition"`
	Materialized bool   `json:"materialized"`
}

func CreateView added in v0.2.6

func CreateView(ctx context.Context, view *View) (*View, error)

func GetView added in v0.2.6

func GetView(ctx context.Context, name string) (*View, error)

func GetViews added in v0.2.6

func GetViews(ctx context.Context) ([]View, error)

type WhereConditionNode

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

Jump to

Keyboard shortcuts

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