Documentation ¶
Index ¶
- Constants
- Variables
- func Asc(field interface{}) string
- func Desc(field interface{}) string
- func DisableDefaultScenario(q *BaseQuery)
- func FieldAlias(schema Schema) func(SchemaField) AliasedSchemaField
- func FieldAutoIncrement(field *BaseSchemaField)
- func FieldPK(field *BaseSchemaField)
- func MakeWritable(record Record)
- func OpEq(a, b interface{}) *eqOperator
- func OpNe(a, b interface{}) *neOperator
- func OpNot(a Sqlizer) *notOperator
- func WrapPK(prefix string, key PrimaryKey) *pkWrapper
- type AliasedSchemaField
- type BaseConnection
- func (conn *BaseConnection) Begin() (*BaseTxRunner, error)
- func (conn *BaseConnection) BeginTx(ctx context.Context, opts *sql.TxOptions) (*BaseTxRunner, error)
- func (conn *BaseConnection) DB() DBProxy
- func (conn *BaseConnection) Exec(query string, args ...interface{}) (sql.Result, error)
- func (conn *BaseConnection) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (conn *BaseConnection) Prepare(query string) (*sql.Stmt, error)
- func (conn *BaseConnection) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- func (conn *BaseConnection) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (conn *BaseConnection) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- type BaseQuery
- func (q *BaseQuery) Builder() (*sq.SelectBuilder, error)
- func (q *BaseQuery) Count() (int64, error)
- func (q *BaseQuery) ExcludeFields(fields ...SchemaField)
- func (q *BaseQuery) For(t SelectForType, lockingType ...SelectForLockingType)
- func (q *BaseQuery) Limit(limit uint64) *BaseQuery
- func (q *BaseQuery) Offset(offset uint64) *BaseQuery
- func (q *BaseQuery) OrderBy(fields ...interface{})
- func (q *BaseQuery) RawQuery() (*sql.Rows, error)
- func (q *BaseQuery) RawQueryContext(ctx context.Context) (*sql.Rows, error)
- func (q *BaseQuery) RawQueryRow() sq.RowScanner
- func (q *BaseQuery) RawQueryRowContext(ctx context.Context) sq.RowScanner
- func (q *BaseQuery) Select(fields ...SchemaField)
- func (q *BaseQuery) Where(pred interface{}, args ...interface{})
- func (q *BaseQuery) With(d interface{})
- type BaseRecordScanner
- type BaseSchema
- type BaseSchemaField
- type BaseStore
- type BaseTxRunner
- func (tx *BaseTxRunner) Commit() error
- func (tx *BaseTxRunner) Exec(query string, args ...interface{}) (sql.Result, error)
- func (tx *BaseTxRunner) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (tx *BaseTxRunner) Prepare(query string) (*sql.Stmt, error)
- func (tx *BaseTxRunner) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- func (tx *BaseTxRunner) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (tx *BaseTxRunner) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (tx *BaseTxRunner) QueryRow(query string, args ...interface{}) *sql.Row
- func (tx *BaseTxRunner) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (tx *BaseTxRunner) Rollback() error
- type CeousOption
- type ColumnAddresser
- type Columnable
- type Condition
- type Connection
- type DBProxy
- type DBRunner
- type Embedded
- type FieldOption
- type Model
- type Pinger
- type PingerContext
- type PrimaryKey
- type Query
- type Record
- type RecordScanner
- type RecordScannerColumns
- type Relation
- type ResultSet
- type Schema
- type SchemaField
- type SelectForLockingType
- type SelectForType
- type Sqlizer
- type Statisticer
- type Transactioner
- type TxProxy
- type ULID
- type Valuer
Constants ¶
const ( // ForUpdate marks a use a FOR UPDATE. ForUpdate = sq.ForUpdate // ForNoKeyUpdate marks a use a FOR NO KEY UPDATE. ForNoKeyUpdate = sq.ForNoKeyUpdate ForShare = sq.ForShare ForKeyShare = sq.ForKeyShare )
const ( // ForUpdateTypeNone will generate the FOR [OPTION] with no modifier. ForUpdateTypeNone = sq.ForUpdateTypeNone // SkipLocked will generate the FOR [OPTION] SKIP LOCKED modifier. SkipLocked = sq.SkipLocked // NoWait will generate the FOR [OPTION] NOWAIT modifier. NoWait = sq.NoWait )
Variables ¶
var ( ErrFieldNotFound = errors.New("field not found") ErrInvalidRecordType = errors.New("invalid record type") ErrInconsistentRelationResult = errors.New("inconsistent relation result") ErrULIDInvalidStringFormat = errors.New("invalid ulid string format") )
var ( ErrNonNewDocument = errors.New("ceous: cannot insert a non new document") ErrNotWritable = errors.New("ceous: record is not writable") ErrNewDocument = errors.New("ceous: cannot updated a new document") ErrNoRowUpdate = errors.New("ceous: update affected no rows") ErrNotFound = errors.New("ceous: entity not found") )
var (
ErrConditionTypeNotSupported = errors.New("condition type not supported")
)
Functions ¶
func DisableDefaultScenario ¶
func DisableDefaultScenario(q *BaseQuery)
DisableDefaultScenario sets the flag IsDefaultScenarioDisabled to true.
TODO(jota): See more DefaultScenario for queries.
func FieldAlias ¶
func FieldAlias(schema Schema) func(SchemaField) AliasedSchemaField
FieldAlias creates a function that will create a SchemaField that will be bound to the schema passed.
func FieldAutoIncrement ¶
func FieldAutoIncrement(field *BaseSchemaField)
func FieldPK ¶
func FieldPK(field *BaseSchemaField)
func MakeWritable ¶
func MakeWritable(record Record)
func WrapPK ¶
func WrapPK(prefix string, key PrimaryKey) *pkWrapper
Types ¶
type AliasedSchemaField ¶
type AliasedSchemaField interface { SchemaField Reference() string }
func NewAliasSchemaField ¶
func NewAliasSchemaField(schema Schema, field SchemaField) AliasedSchemaField
type BaseConnection ¶
type BaseConnection struct {
// contains filtered or unexported fields
}
func NewConnection ¶
func NewConnection(db DBProxy) *BaseConnection
NewConnection will create a new instance of the `*BaseConnection`.
func (*BaseConnection) Begin ¶
func (conn *BaseConnection) Begin() (*BaseTxRunner, error)
Begin starts a transaction.
func (*BaseConnection) BeginTx ¶
func (conn *BaseConnection) BeginTx(ctx context.Context, opts *sql.TxOptions) (*BaseTxRunner, error)
BeginTx starts a transaction with more options.
func (*BaseConnection) DB ¶
func (conn *BaseConnection) DB() DBProxy
DB returns the real connection object for the database connection.
func (*BaseConnection) Exec ¶
func (conn *BaseConnection) Exec(query string, args ...interface{}) (sql.Result, error)
func (*BaseConnection) ExecContext ¶
func (*BaseConnection) Prepare ¶
func (conn *BaseConnection) Prepare(query string) (*sql.Stmt, error)
func (*BaseConnection) PrepareContext ¶
func (*BaseConnection) Query ¶
func (conn *BaseConnection) Query(query string, args ...interface{}) (*sql.Rows, error)
func (*BaseConnection) QueryContext ¶
type BaseQuery ¶
type BaseQuery struct { Schema Schema Runner DBRunner Relations []Relation RecordScanner RecordScanner IsDefaultScenarioDisabled bool // contains filtered or unexported fields }
func NewBaseQuery ¶
func NewBaseQuery(options ...CeousOption) *BaseQuery
func (*BaseQuery) Builder ¶
func (q *BaseQuery) Builder() (*sq.SelectBuilder, error)
Builder will prepare a *sq.SelectBuilder and return it with all fields, conditions and limits.
func (*BaseQuery) ExcludeFields ¶
func (q *BaseQuery) ExcludeFields(fields ...SchemaField)
func (*BaseQuery) For ¶
func (q *BaseQuery) For(t SelectForType, lockingType ...SelectForLockingType)
func (*BaseQuery) Limit ¶
Limit will update the limit directive of this query.
Warning: If you use the method `Builder` directly, be aware that this will affect the builder returned.
func (*BaseQuery) Offset ¶
Offset will update the offset directive of this query.
Warning: If you use the method `Builder` directly, be aware that this will affect the builder returned.
func (*BaseQuery) RawQueryContext ¶
func (*BaseQuery) RawQueryRow ¶
func (q *BaseQuery) RawQueryRow() sq.RowScanner
func (*BaseQuery) RawQueryRowContext ¶
func (q *BaseQuery) RawQueryRowContext(ctx context.Context) sq.RowScanner
func (*BaseQuery) Select ¶
func (q *BaseQuery) Select(fields ...SchemaField)
type BaseRecordScanner ¶
type BaseRecordScanner struct{}
BaseRecordScanner implements a basic and generic `RecordScanner`.
var DefaultRecordScanner BaseRecordScanner
func (*BaseRecordScanner) ScanRecord ¶
func (recordScanner *BaseRecordScanner) ScanRecord(rs ResultSet, model Record) error
ScanRecord uses the ColumnAddress to read records from the given `rs`.
type BaseSchema ¶
type BaseSchema struct { ColumnsArr []SchemaField // contains filtered or unexported fields }
func NewBaseSchema ¶
func NewBaseSchema(tableName, alias string, columns ...SchemaField) *BaseSchema
func (*BaseSchema) Alias ¶
func (schema *BaseSchema) Alias() string
func (*BaseSchema) As ¶
func (schema *BaseSchema) As(alias string) Schema
func (*BaseSchema) Columns ¶
func (schema *BaseSchema) Columns() []SchemaField
func (*BaseSchema) PrimaryKey ¶
func (schema *BaseSchema) PrimaryKey() SchemaField
func (*BaseSchema) Table ¶
func (schema *BaseSchema) Table() string
type BaseSchemaField ¶
type BaseSchemaField struct {
// contains filtered or unexported fields
}
func NewSchemaField ¶
func NewSchemaField(name string, options ...FieldOption) *BaseSchemaField
func (*BaseSchemaField) IsAutoInc ¶
func (field *BaseSchemaField) IsAutoInc() bool
func (*BaseSchemaField) IsPK ¶
func (field *BaseSchemaField) IsPK() bool
func (*BaseSchemaField) QualifiedName ¶
func (field *BaseSchemaField) QualifiedName(schema Schema) string
func (*BaseSchemaField) String ¶
func (field *BaseSchemaField) String() string
type BaseStore ¶
type BaseStore struct {
// contains filtered or unexported fields
}
BaseStore is the generic implementation of the Store.
TODO(jota): To document it...
func NewStore ¶
func NewStore(schema Schema, options ...CeousOption) *BaseStore
NewStore returns a new base implementation of a Store. That does not aims to be used by itself, but to be used as composition on real stores.
TODO(jota): Improve documentation.
type BaseTxRunner ¶
type BaseTxRunner struct {
// contains filtered or unexported fields
}
func (*BaseTxRunner) Commit ¶
func (tx *BaseTxRunner) Commit() error
func (*BaseTxRunner) Exec ¶
func (tx *BaseTxRunner) Exec(query string, args ...interface{}) (sql.Result, error)
func (*BaseTxRunner) ExecContext ¶
func (*BaseTxRunner) PrepareContext ¶
func (*BaseTxRunner) Query ¶
func (tx *BaseTxRunner) Query(query string, args ...interface{}) (*sql.Rows, error)
func (*BaseTxRunner) QueryContext ¶
func (*BaseTxRunner) QueryRow ¶
func (tx *BaseTxRunner) QueryRow(query string, args ...interface{}) *sql.Row
func (*BaseTxRunner) QueryRowContext ¶
func (*BaseTxRunner) Rollback ¶
func (tx *BaseTxRunner) Rollback() error
type CeousOption ¶
type CeousOption func(q interface{})
func WithConn ¶
func WithConn(conn Connection) CeousOption
WithConn returns a query option for creating .
func WithRunner ¶
func WithRunner(runner DBRunner) CeousOption
WithRunner returns a query option for setting the runner for a transaction.
func WithSchema ¶
func WithSchema(schema Schema) CeousOption
WithSchema returns a query option that will set the schema of a Query. Useful for using aliases.
type ColumnAddresser ¶
Valuer ...
type Columnable ¶
type Columnable interface {
Columns() []SchemaField
}
type Condition ¶
func Eq ¶
func Eq(field SchemaField, value interface{}) Condition
func Ne ¶
func Ne(field SchemaField, value interface{}) Condition
func SqlCondition ¶
SqlCondition will return a new condition that will create a sqlCondition.
See more at sqlCondition
type Connection ¶
type Connection interface {
DB() DBProxy
}
type DBProxy ¶
type DBProxy interface { DBRunner io.Closer Statisticer Transactioner }
type DBRunner ¶
type DBRunner interface { sq.Execer sq.ExecerContext sq.Queryer sq.QueryerContext sq.Preparer }
type FieldOption ¶
type FieldOption func(*BaseSchemaField)
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Valuer ...
func (*Model) IsPersisted ¶
func (*Model) IsWritable ¶
type PingerContext ¶
type PrimaryKey ¶
type PrimaryKey interface { Columnable ColumnAddresser Valuer }
type Record ¶
type Record interface { GetID() interface{} IsPersisted() bool IsWritable() bool ColumnAddresser Valuer // contains filtered or unexported methods }
Valuer ...
type RecordScanner ¶
RecordScanner describes a scanner for a record.
type RecordScannerColumns ¶
type RecordScannerColumns interface {
SelectColumns() []SchemaField
}
RecordScannerColumns describes a column selector.
type ResultSet ¶
type ResultSet interface { Next() bool Scan(dest ...interface{}) error Columns() ([]string, error) io.Closer }
ResultSet represents the abstraction of a sql.ResultSet struct.
type Schema ¶
type Schema interface { PrimaryKey() SchemaField Alias() string Table() string As(string) Schema Columnable }
type SchemaField ¶
type SelectForLockingType ¶
type SelectForLockingType = sq.SelectForLockingType
type SelectForType ¶
type SelectForType = sq.SelectForType
type Statisticer ¶
type Transactioner ¶
type ULID ¶
ULID is an ID type provided by kallax that is a lexically sortable UUID. The internal representation is an ULID (https://github.com/oklog/ulid). It already implements sql.Scanner and driver.Valuer, so it's perfectly safe for database usage.
This ULID implementation was copied from the go-kallax library (https://github.com/src-d/go-kallax/blob/c3e1e4d85f44dd6ed4f0b65c7fed60c0c576ba85/model.go).
func MustNewULID ¶
func MustNewULID() ULID
MustNewULID returns a new ULID, which is a lexically sortable UUID.
func NewULIDFromText ¶
NewULIDFromText creates a new ULID from its string representation. Will return an error if the text is not a valid ULID.
func (ULID) IsEmpty ¶
IsEmpty returns whether the ID is empty or not. An empty ID means it has not been set yet.
func (ULID) MarshalText ¶
MarshalText serializes an ULID for JSON.
func (*ULID) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface. Following formats are supported: "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}", "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8" Implements the exact same code as the UUID UnmarshalText removing the version check.