Documentation
¶
Overview ¶
Package makroud provides a high level SQL Connector. At the moment, only PostgreSQL is supported.
It's an advanced mapper and/or a lightweight ORM that relies on reflection.
For further informations, you can read this documentation: https://github.com/ulule/makroud/blob/master/README.md
Or you can discover makroud with these examples. First, you have to create a driver:
driver, err := makroud.New(
makroud.Host(cfg.Host),
makroud.Port(cfg.Port),
makroud.User(cfg.User),
makroud.Password(cfg.Password),
makroud.Database(cfg.Name),
makroud.SSLMode(cfg.SSLMode),
makroud.MaxOpenConnections(cfg.MaxOpenConnections),
makroud.MaxIdleConnections(cfg.MaxIdleConnections),
)
Then, define a model:
type User struct {
ID string `makroud:"column:id,pk:ulid"`
Email string `makroud:"column:email"`
Password string `makroud:"column:password"`
Country string `makroud:"column:country"`
Locale string `makroud:"column:locale"`
}
Execute an insert:
user := &User{
Email: "gilles@ulule.com",
Password: "019a7bdf56b9f48e18096d62b21f",
Country: "FR",
Locale: "fr",
}
err := makroud.Save(ctx, driver, user)
Or an update:
user.Email = "gilles.fabio@ulule.com" err := makroud.Save(ctx, driver, user)
Or execute a simple query without model:
import "github.com/ulule/loukoum/v3"
list := []string{}
stmt := loukoum.Update("users").
Set(
loukoum.Pair("updated_at", loukoum.Raw("NOW()")),
loukoum.Pair("status", status),
).
Where(loukoum.Condition("group_id").Equal(gid)).
Returning("id")
err := makroud.Exec(ctx, driver, stmt, &list)
Index ¶
- Constants
- Variables
- func Archive(ctx context.Context, driver Driver, model Model) error
- func Count(ctx context.Context, driver Driver, stmt builder.Builder) (int64, error)
- func DebugField(field Field) string
- func DebugTag(tag Tag) string
- func DebugTagProperty(prop TagProperty) string
- func DebugTags(tags Tags) string
- func Delete(ctx context.Context, driver Driver, model Model) error
- func Exec(ctx context.Context, driver Driver, stmt builder.Builder, dest ...interface{}) error
- func FloatCount(ctx context.Context, driver Driver, stmt builder.Builder) (float64, error)
- func GenerateULID(driver Driver) string
- func GenerateUUIDV1(driver Driver) string
- func GenerateUUIDV4(driver Driver) string
- func IsErrNoRows(err error) bool
- func Log(driver Driver, queries Queries, duration time.Duration)
- func Preload(ctx context.Context, driver Driver, out interface{}, ...) error
- func RawExec(ctx context.Context, driver Driver, query string, dest ...interface{}) error
- func Retry(handler func(Driver) error, drivers ...Driver) (err error)
- func Save(ctx context.Context, driver Driver, model Model) error
- func Transaction(driver Driver, handler func(driver Driver) error) error
- type AssociationType
- type Client
- func (c *Client) Begin() (Driver, error)
- func (c *Client) Close() error
- func (c *Client) Commit() error
- func (c *Client) DriverName() string
- func (c *Client) Exec(ctx context.Context, query string, args ...interface{}) error
- func (c *Client) FindAll(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (c *Client) FindOne(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (c *Client) MustExec(ctx context.Context, query string, args ...interface{})
- func (c *Client) MustQuery(ctx context.Context, query string, arg interface{}) Rows
- func (c *Client) Ping() error
- func (c *Client) Prepare(ctx context.Context, query string) (Statement, error)
- func (c *Client) Query(ctx context.Context, query string, arg interface{}) (Rows, error)
- func (c *Client) Rollback() error
- type ClientOptions
- type Columns
- type Driver
- type FKType
- type Field
- func (field Field) ColumnName() string
- func (field Field) ColumnPath() string
- func (field Field) FieldIndex() []int
- func (field Field) FieldName() string
- func (field Field) ForeignKey() string
- func (field Field) HasDefault() bool
- func (field Field) HasRelation() bool
- func (field Field) HasULID() bool
- func (field Field) HasUUIDV1() bool
- func (field Field) HasUUIDV4() bool
- func (field Field) IsAssociation() bool
- func (field Field) IsAssociationType(kind AssociationType) bool
- func (field Field) IsCreatedKey() bool
- func (field Field) IsDeletedKey() bool
- func (field Field) IsExcluded() bool
- func (field Field) IsForeignKey() bool
- func (field Field) IsPrimaryKey() bool
- func (field Field) IsUpdatedKey() bool
- func (field Field) ModelName() string
- func (field Field) RelationName() string
- func (field Field) String() string
- func (field Field) TableName() string
- func (field Field) Type() reflect.Type
- type ForeignKey
- type Logger
- type Mapper
- type Model
- type ModelOpts
- type Option
- func Cache(enabled bool) Option
- func Database(dbname string) Option
- func DisableSSL() Option
- func EnableSSL() Option
- func EnableSavepoint() Option
- func Host(host string) Option
- func MaxIdleConnections(maximum int) Option
- func MaxOpenConnections(maximum int) Option
- func Password(password string) Option
- func Port(port int) Option
- func SSLMode(mode string) Option
- func Timezone(timezone string) Option
- func User(user string) Option
- func WithLogger(logger Logger) Option
- type PKType
- type PreloadHandler
- type PrimaryKey
- type PrimaryKeyDefault
- type Queries
- type Query
- type Reference
- type ReferenceObject
- func (object ReferenceObject) ColumnName() string
- func (object ReferenceObject) ColumnPath() string
- func (object ReferenceObject) Columns() []string
- func (object ReferenceObject) DeletedKeyName() string
- func (object ReferenceObject) DeletedKeyPath() string
- func (object ReferenceObject) FieldName() string
- func (object ReferenceObject) ForeignKeyType() FKType
- func (object ReferenceObject) HasDeletedKey() bool
- func (object ReferenceObject) IsForeignKey() bool
- func (object ReferenceObject) IsPrimaryKey() bool
- func (object ReferenceObject) Model() Model
- func (object ReferenceObject) ModelName() string
- func (object ReferenceObject) PrimaryKeyType() PKType
- func (object ReferenceObject) Schema() *Schema
- func (object ReferenceObject) TableName() string
- type Row
- type Rows
- type Schema
- func (schema Schema) ColumnPaths() Columns
- func (schema Schema) Columns() Columns
- func (schema Schema) CreatedKeyName() string
- func (schema Schema) CreatedKeyPath() string
- func (schema Schema) DeletedKeyName() string
- func (schema Schema) DeletedKeyPath() string
- func (schema Schema) HasColumn(column string) bool
- func (schema Schema) HasCreatedKey() bool
- func (schema Schema) HasDeletedKey() bool
- func (schema Schema) HasUpdatedKey() bool
- func (schema Schema) Model() Model
- func (schema Schema) ModelName() string
- func (schema Schema) PrimaryKey() PrimaryKey
- func (schema Schema) ScanRow(row Row, model Model) error
- func (schema Schema) ScanRows(rows Rows, model Model) error
- func (schema Schema) TableName() string
- func (schema Schema) UpdatedKeyName() string
- func (schema Schema) UpdatedKeyPath() string
- type Selector
- func (selector *Selector) Close() error
- func (selector *Selector) Ping() error
- func (selector *Selector) RetryAliases(handler func(Driver) error, aliases ...string) error
- func (selector *Selector) RetryMaster(handler func(Driver) error) error
- func (selector *Selector) Using(alias string) (Driver, error)
- type SelectorConfigurations
- type Statement
- type Tag
- type TagProperty
- type Tags
- type TagsAnalyzerOption
- type TagsAnalyzerOptions
Constants ¶
const ( // FKUnknownType is an unknown foreign key. FKUnknownType = FKType(iota) // FKIntegerType uses an integer as foreign key. FKIntegerType // ForeignKeyString uses a string as foreign key. FKStringType // FKOptionalIntegerType uses an optional integer as foreign key. FKOptionalIntegerType // FKOptionalStringType uses an optional string as foreign key. FKOptionalStringType )
Foreign key types.
const ( AssociationTypeUndefined = AssociationType(iota) AssociationTypeOne AssociationTypeMany )
Association types.
const ( // PKUnknownType is an unknown primary key. PKUnknownType = PKType(iota) // PKIntegerType uses an integer as primary key. PKIntegerType // PrimaryKeyString uses a string as primary key. PKStringType )
Primary key types.
const ( // PrimaryKeyDBDefault uses internal db mechanism to define primary key value. PrimaryKeyDBDefault = PrimaryKeyDefault(iota) // PrimaryKeyULIDDefault uses a ulid generator to define primary key value. PrimaryKeyULIDDefault // PrimaryKeyUUIDV1Default uses a uuid v1 generator to define primary key value. PrimaryKeyUUIDV1Default // PrimaryKeyUUIDV4Default uses a uuid v4 generator to define primary key value. PrimaryKeyUUIDV4Default )
PrimaryKey default types.
const ( // TagName defines makroud tag namespace. TagName = "makroud" // TagNameShort defines makroud tag namespace in short version. TagNameShort = "mk" // TagNameAlt defines sqlx tag namespace for backward compatibility. TagNameAlt = "db" )
const ( TagKeyIgnored = "-" TagKeyDefault = "default" TagKeyColumn = "column" TagKeyColumnShort = "col" TagKeyForeignKey = "fk" TagKeyPrimaryKey = "pk" TagKeyRelation = "relation" TagKeyRelationShort = "rel" TagKeyULID = "ulid" TagKeyUUIDV1 = "uuid-v1" TagKeyUUIDV4 = "uuid-v4" )
Tag modifiers on Model.
const ClientDriver = "postgres"
ClientDriver define the driver name used in makroud.
const DefaultSelector = MasterSelector
DefaultSelector defines the default selector alias.
const MasterSelector = "master"
MasterSelector defines the master alias.
const SlaveSelector = "slave"
SlaveSelector defines the slave alias.
Variables ¶
var ( // ErrNoRows is returned when query doesn't return a row. ErrNoRows = fmt.Errorf("no rows in result set") // ErrInvalidDriver is returned when given driver is undefined. ErrInvalidDriver = fmt.Errorf("a makroud driver is required") // ErrPointerRequired is returned when given value is not a pointer. ErrPointerRequired = fmt.Errorf("a pointer is required") // ErrStructRequired is returned when given value is not a struct. ErrStructRequired = fmt.Errorf("a struct is required") // ErrSchemaColumnRequired is returned when we cannot find a column in current schema. ErrSchemaColumnRequired = fmt.Errorf("cannot find column in schema") // ErrSchemaCreatedKey is returned when we cannot find a created key in given schema. ErrSchemaCreatedKey = fmt.Errorf("cannot find created key in schema") // ErrSchemaUpdatedKey is returned when we cannot find a updated key in given schema. ErrSchemaUpdatedKey = fmt.Errorf("cannot find updated key in schema") // ErrSchemaDeletedKey is returned when we cannot find a deleted key in given schema. ErrSchemaDeletedKey = fmt.Errorf("cannot find deleted key in schema") // ErrPreloadInvalidSchema is returned when preload detect an invalid schema from given model. ErrPreloadInvalidSchema = fmt.Errorf("given model has an invalid schema") // ErrPreloadInvalidModel is returned when preload detect an invalid model. ErrPreloadInvalidModel = fmt.Errorf("given model is invalid") // ErrPreloadInvalidPath is returned when preload detect an invalid path. ErrPreloadInvalidPath = fmt.Errorf("given path is invalid") // ErrSelectorNotFoundConnection is returned when the required connection does not exists in selector connections. ErrSelectorNotFoundConnection = fmt.Errorf("cannot find connection in selector") // ErrSelectorMissingRetryConnection is returned when the retry mechanism has no connection available from selector. ErrSelectorMissingRetryConnection = fmt.Errorf("cannot find a healthy connection in selector") )
Makroud general errors.
var TagsKeyMapper = map[string]string{ TagKeyColumnShort: TagKeyColumn, TagKeyRelationShort: TagKeyRelation, }
TagsKeyMapper is a mapper that convert tag key to another key (aliasing).
var TagsList = []string{ TagName, TagNameShort, TagNameAlt, }
TagsList is a list of supported tags, this include sqlx and makroud one.
var TagsNameMapper = map[string]string{ TagNameAlt: TagKeyColumn, }
TagsNameMapper is a mapper that convert supported tag name to makroud one (migrate).
Functions ¶
func DebugField ¶
DebugField returns a human readable version of given instance.
func DebugTagProperty ¶
func DebugTagProperty(prop TagProperty) string
DebugTagProperty returns a human readable version of given instance.
func Exec ¶
Exec will execute given query from a Loukoum builder. If an object is given, it will mutate it to match the row values.
func FloatCount ¶
FloatCount will execute given query to return a number (in float) from a aggregate function.
func GenerateUUIDV1 ¶
GenerateUUIDV1 generates a new uuid v1.
func GenerateUUIDV4 ¶
GenerateUUIDV4 generates a new uuid v4.
func IsErrNoRows ¶
IsErrNoRows returns if given error is a "no rows" error.
func Preload ¶
func Preload(ctx context.Context, driver Driver, out interface{}, handlers ...PreloadHandler) error
Preload preloads related fields.
func RawExec ¶
RawExec will execute given query. If an object is given, it will mutate it to match the row values.
Types ¶
type AssociationType ¶
type AssociationType uint8
AssociationType define an association type.
func (AssociationType) String ¶
func (e AssociationType) String() string
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a wrapper that can interact with the database, it's an implementation of Driver.
func NewDebugClient ¶
NewDebugClient returns a new client with a specific engine. Use this with extreme caution, please use New() or NewWithOptions() instead...
func NewWithOptions ¶
func NewWithOptions(options *ClientOptions) (*Client, error)
NewWithOptions returns a new Client instance.
func (*Client) DriverName ¶
DriverName returns the driver name used by this driver.
func (*Client) FindAll ¶
func (c *Client) FindAll(ctx context.Context, dest interface{}, query string, args ...interface{}) error
FindAll executes this named statement to fetch a list of records. Output must be a pointer to a slice of value.
func (*Client) FindOne ¶
func (c *Client) FindOne(ctx context.Context, dest interface{}, query string, args ...interface{}) error
FindOne executes this named statement to fetch one record. If there is no row, an error is returned. Output must be a pointer to a value.
func (*Client) MustExec ¶
MustExec executes a named statement using given arguments. If an error has occurred, it panics.
func (*Client) MustQuery ¶
MustQuery executes a named statement that returns rows using given arguments. If an error has occurred, it panics.
func (*Client) Prepare ¶
Prepare creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement.
type ClientOptions ¶
type ClientOptions struct {
Port int
Host string
User string
Password string
DBName string
SSLMode string
Timezone string
MaxOpenConnections int
MaxIdleConnections int
WithCache bool
SavepointEnabled bool
Logger Logger
}
ClientOptions configure a Client instance.
func NewClientOptions ¶
func NewClientOptions() *ClientOptions
NewClientOptions creates a new ClientOptions instance with default options.
func (ClientOptions) String ¶
func (e ClientOptions) String() string
type Columns ¶
type Columns []string
Columns is a list of table columns.
func GetColumns ¶
GetColumns returns a comma-separated string representation of a model's table columns.
type Driver ¶
type Driver interface {
// Exec executes a named statement using given arguments.
Exec(ctx context.Context, query string, args ...interface{}) error
// MustExec executes a named statement using given arguments.
// If an error has occurred, it panics.
MustExec(ctx context.Context, query string, args ...interface{})
// Query executes a named statement that returns rows using given arguments.
Query(ctx context.Context, query string, arg interface{}) (Rows, error)
// MustQuery executes a named statement that returns rows using given arguments.
// If an error has occurred, it panics.
MustQuery(ctx context.Context, query string, arg interface{}) Rows
// Prepare creates a prepared statement for later queries or executions.
// Multiple queries or executions may be run concurrently from the returned statement.
Prepare(ctx context.Context, query string) (Statement, error)
// FindOne executes this named statement to fetch one record.
// If there is no row, an error is returned.
// Output must be a pointer to a value.
FindOne(ctx context.Context, dest interface{}, query string, args ...interface{}) error
// FindAll executes this named statement to fetch a list of records.
// Output must be a pointer to a slice of value.
FindAll(ctx context.Context, dest interface{}, query string, args ...interface{}) error
// Close closes the underlying connection.
Close() error
// Ping verifies that the underlying connection is healthy.
Ping() error
// DriverName returns the driver name used by this driver.
DriverName() string
// Begin a new transaction.
Begin() (Driver, error)
// Rollback the associated transaction.
Rollback() error
// Commit the associated transaction.
Commit() error
// contains filtered or unexported methods
}
Driver is a high level abstraction of a database connection or a transaction.
type FKType ¶
type FKType uint8
FKType define a foreign key type.
func (FKType) IsCompatible ¶
IsCompatible returns if given primary key is compatible with foreign key.
func (FKType) IsOptional ¶
IsOptional returns if foreign key has an optional type.
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field defines the column name, field and options from model.
For example: If we have an User, we could have this primary key defined in User's schema.
Field {
ModelName: User,
TableName: users,
FieldName: AvatarID,
ColumnName: avatar_id,
ColumnPath: users.avatar_id,
}
func NewField ¶
func NewField(driver Driver, schema *Schema, model Model, name string, args ...ModelOpts) (*Field, error)
NewField creates a new field using given model and name.
func (Field) ColumnName ¶
ColumnName returns the field's column name.
func (Field) ColumnPath ¶
ColumnPath returns the field's full column path.
func (Field) FieldIndex ¶
FieldIndex define the struct field index used for this field.
func (Field) ForeignKey ¶
ForeignKey returns the field foreign key's table name.
func (Field) HasDefault ¶
HasDefault returns if the field has a default value and should be in returning statement.
func (Field) HasRelation ¶
HasRelation returns if the field has a explicit relation.
func (Field) IsAssociation ¶
IsAssociation returns if the field is an association.
func (Field) IsAssociationType ¶
func (field Field) IsAssociationType(kind AssociationType) bool
IsAssociationType returns if the field has given association type.
func (Field) IsCreatedKey ¶
IsCreatedKey returns if the field is a created key.
func (Field) IsDeletedKey ¶
IsDeletedKey returns if the field is a deleted key.
func (Field) IsExcluded ¶
IsExcluded returns if the field excluded. (anonymous, private...)
func (Field) IsForeignKey ¶
IsForeignKey returns if the field is a foreign key.
func (Field) IsPrimaryKey ¶
IsPrimaryKey returns if the field is a primary key.
func (Field) IsUpdatedKey ¶
IsUpdatedKey returns if the field is a updated key.
func (Field) RelationName ¶
RelationName returns the field relation name.
type ForeignKey ¶
type ForeignKey struct {
Field
// contains filtered or unexported fields
}
ForeignKey is a composite object that define a foreign key for a model. This foreign key will be used later for Preload...
For example: If we have an User, we could have this primary key defined in User's schema.
ForeignKey {
ModelName: User,
TableName: users,
FieldName: AvatarID,
ColumnName: avatar_id,
ColumnPath: users.avatar_id,
Reference: avatars,
Type: int64,
}
func NewForeignKey ¶
func NewForeignKey(field *Field) (*ForeignKey, error)
NewForeignKey creates a foreign key from a field instance.
func (ForeignKey) Reference ¶
func (key ForeignKey) Reference() string
Reference returns the foreign key's table name.
type Logger ¶
type Logger interface {
// Log push what query was executed and its duration.
Log(query string, duration time.Duration)
}
Logger is an observer that collect queries executed in makroud.
type Mapper ¶
type Mapper map[string]interface{}
Mapper will be used to mutate a Model with row values.
type Option ¶
type Option func(*ClientOptions) error
Option is used to define Client configuration.
func DisableSSL ¶
func DisableSSL() Option
DisableSSL will configure the Client to disable SSL mode.
func EnableSavepoint ¶
func EnableSavepoint() Option
EnableSavepoint will enable the SAVEPOINT postgresql feature.
func MaxIdleConnections ¶
MaxIdleConnections will configure the Client to keep this maximum number of idle connections in the connection pool.
func MaxOpenConnections ¶
MaxOpenConnections will configure the Client to use this maximum number of open connections to the database.
type PKType ¶
type PKType uint8
PKType define a primary key type.
func (PKType) IsCompatible ¶
IsCompatible returns if given foreign key is compatible with primary key.
type PreloadHandler ¶
type PreloadHandler struct {
// contains filtered or unexported fields
}
PreloadHandler defines what resources should be preloaded.
func WithPreloadCallback ¶
func WithPreloadCallback(field string, callback func(query builder.Select) builder.Select) PreloadHandler
WithPreloadCallback returns a handler that preload a field with conditions.
func WithPreloadField ¶
func WithPreloadField(field string) PreloadHandler
WithPreloadField returns a handler that preload a field.
func WithUnscopedPreload ¶
func WithUnscopedPreload(handler PreloadHandler) PreloadHandler
WithUnscopedPreload unscopes given preload handler.
type PrimaryKey ¶
type PrimaryKey struct {
Field
// contains filtered or unexported fields
}
PrimaryKey is a composite object that define a primary key for a model.
For example: If we have an User, we could have this primary key defined in User's schema.
PrimaryKey {
ModelName: User,
TableName: users,
FieldName: ID,
ColumnName: id,
ColumnPath: users.id,
Type: int64,
Default: db,
}
func NewPrimaryKey ¶
func NewPrimaryKey(field *Field) (*PrimaryKey, error)
NewPrimaryKey creates a primary key from a field instance.
func (PrimaryKey) Default ¶
func (key PrimaryKey) Default() PrimaryKeyDefault
Default returns the primary key's default mechanism.
func (PrimaryKey) Value ¶
func (key PrimaryKey) Value(model Model) (interface{}, error)
Value returns the primary key's value, or an error if undefined.
func (PrimaryKey) ValueOpt ¶
func (key PrimaryKey) ValueOpt(model Model) (interface{}, bool)
ValueOpt may returns the primary key's value, if defined.
type PrimaryKeyDefault ¶
type PrimaryKeyDefault uint8
PrimaryKeyDefault define how primary key value is generated.
func (PrimaryKeyDefault) String ¶
func (e PrimaryKeyDefault) String() string
type Query ¶
Query is a query generated by loukoum and makroud.
func NewRawQuery ¶
NewRawQuery creates a new Query instance from given query.
type Reference ¶
type Reference struct {
Field
// contains filtered or unexported fields
}
Reference defines a model relationship.
func NewReference ¶
NewReference creates a reference from a field instance.
func (Reference) IsLocal ¶
IsLocal returns if reference is local from the model, or from another model (remote).
func (Reference) Local ¶
func (reference Reference) Local() ReferenceObject
Local returns the local model.
func (Reference) Remote ¶
func (reference Reference) Remote() ReferenceObject
Remote returns the remote model.
type ReferenceObject ¶
type ReferenceObject struct {
// contains filtered or unexported fields
}
ReferenceObject defines a model used by Reference.
func (ReferenceObject) ColumnName ¶
func (object ReferenceObject) ColumnName() string
ColumnName returns the column name of this reference.
func (ReferenceObject) ColumnPath ¶
func (object ReferenceObject) ColumnPath() string
ColumnPath returns the full column path of this reference.
func (ReferenceObject) Columns ¶
func (object ReferenceObject) Columns() []string
Columns returns this reference columns.
func (ReferenceObject) DeletedKeyName ¶
func (object ReferenceObject) DeletedKeyName() string
DeletedKeyName returns reference schema deleted key column name.
func (ReferenceObject) DeletedKeyPath ¶
func (object ReferenceObject) DeletedKeyPath() string
DeletedKeyPath returns reference schema deleted key column path.
func (ReferenceObject) FieldName ¶
func (object ReferenceObject) FieldName() string
FieldName returns the field name of this reference.
func (ReferenceObject) ForeignKeyType ¶
func (object ReferenceObject) ForeignKeyType() FKType
ForeignKeyType returns this reference foreign key type.
func (ReferenceObject) HasDeletedKey ¶
func (object ReferenceObject) HasDeletedKey() bool
HasDeletedKey returns if an deleted key is defined for this reference.
func (ReferenceObject) IsForeignKey ¶
func (object ReferenceObject) IsForeignKey() bool
IsForeignKey returns if this reference is a foreign key.
func (ReferenceObject) IsPrimaryKey ¶
func (object ReferenceObject) IsPrimaryKey() bool
IsPrimaryKey returns if this reference is a primary key.
func (ReferenceObject) Model ¶
func (object ReferenceObject) Model() Model
Model returns the reference model.
func (ReferenceObject) ModelName ¶
func (object ReferenceObject) ModelName() string
ModelName returns the model name of this reference.
func (ReferenceObject) PrimaryKeyType ¶
func (object ReferenceObject) PrimaryKeyType() PKType
PrimaryKeyType returns this reference primary key type.
func (ReferenceObject) Schema ¶
func (object ReferenceObject) Schema() *Schema
Schema returns the reference schema.
func (ReferenceObject) TableName ¶
func (object ReferenceObject) TableName() string
TableName returns the table name of this reference.
type Row ¶
type Row interface {
// Write copies the columns in the current row into the given map.
Write(dest map[string]interface{}) error
// Columns returns the column names.
Columns() ([]string, error)
// Scan copies the columns in the current row into the values pointed at by dest.
// The number of values in dest must be the same as the number of columns in Rows.
Scan(dest ...interface{}) error
}
A Row is a simple row.
type Rows ¶
type Rows interface {
// Next prepares the next result row for reading with the MapScan method.
// It returns true on success, or false if there is no next result row or an error
// happened while preparing it.
// Err should be consulted to distinguish between the two cases.
// Every call to MapScan, even the first one, must be preceded by a call to Next.
Next() bool
// Close closes the Rows, preventing further enumeration/iteration.
// If Next is called and returns false and there are no further result sets, the Rows are closed automatically
// and it will suffice to check the result of Err.
Close() error
// Err returns the error, if any, that was encountered during iteration.
// Err may be called after an explicit or implicit Close.
Err() error
// Write copies the columns in the current row into the given map.
Write(dest map[string]interface{}) error
// Columns returns the column names.
Columns() ([]string, error)
// Scan copies the columns in the current row into the values pointed at by dest.
// The number of values in dest must be the same as the number of columns in Rows.
Scan(dest ...interface{}) error
}
A Rows is an iteratee of a list of records.
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema is a model schema.
func GetSchema ¶
GetSchema returns the schema from given model. If the schema does not exists, it returns an error.
func (Schema) ColumnPaths ¶
ColumnPaths returns schema column with table prefix.
func (Schema) CreatedKeyName ¶
CreatedKeyName returns schema created key column name.
func (Schema) CreatedKeyPath ¶
CreatedKeyPath returns schema created key column path.
func (Schema) DeletedKeyName ¶
DeletedKeyName returns schema deleted key column name.
func (Schema) DeletedKeyPath ¶
DeletedKeyPath returns schema deleted key column path.
func (Schema) HasCreatedKey ¶
HasCreatedKey returns if a created key is defined for current schema.
func (Schema) HasDeletedKey ¶
HasDeletedKey returns if a deleted key is defined for current schema.
func (Schema) HasUpdatedKey ¶
HasUpdatedKey returns if an updated key is defined for current schema.
func (Schema) PrimaryKey ¶
func (schema Schema) PrimaryKey() PrimaryKey
PrimaryKey returns the schema primary key.
func (Schema) UpdatedKeyName ¶
UpdatedKeyName returns schema deleted key column name.
func (Schema) UpdatedKeyPath ¶
UpdatedKeyPath returns schema updated key column path.
type Selector ¶
type Selector struct {
// contains filtered or unexported fields
}
Selector contains a pool of drivers indexed by their name.
func NewSelector ¶
func NewSelector(configurations map[string]*ClientOptions) (*Selector, error)
NewSelector returns a new selector containing a pool of drivers with given configuration.
func NewSelectorWithDriver ¶
NewSelectorWithDriver returns a new selector containing the given connection.
func (*Selector) RetryAliases ¶
RetryAliases is an helper calling Retry with a list of aliases.
func (*Selector) RetryMaster ¶
RetryMaster is an helper calling RetryAliases with a slave then a master connection.
type SelectorConfigurations ¶
type SelectorConfigurations map[string]*ClientOptions
SelectorConfigurations define a list of configurations for a pool of drivers.
type Statement ¶
type Statement interface {
// Close closes the statement.
Close() error
// Exec executes this named statement using the struct passed.
Exec(ctx context.Context, args []interface{}) error
// QueryRow executes this named statement returning a single row.
QueryRow(ctx context.Context, args []interface{}) (Row, error)
// QueryRows executes this named statement returning a list of rows.
QueryRows(ctx context.Context, args []interface{}) (Rows, error)
// FindOne executes this named statement to fetch one record.
// If there is no row, an error is returned.
// Output must be a pointer to a value.
FindOne(ctx context.Context, dest interface{}, args []interface{}) error
// FindAll executes this named statement to fetch a list of records.
// Output must be a pointer to a slice of value.
FindAll(ctx context.Context, dest interface{}, args []interface{}) error
}
A Statement from prepare.
type Tag ¶
type Tag struct {
// contains filtered or unexported fields
}
Tag is tag defined in a model.
func (Tag) Properties ¶
func (tag Tag) Properties() []TagProperty
Properties returns tag properties.
type TagProperty ¶
type TagProperty struct {
// contains filtered or unexported fields
}
TagProperty is a struct tag property.
func (TagProperty) String ¶
func (prop TagProperty) String() string
String returns a human readable version of current instance.
type Tags ¶
type Tags []Tag
Tags is a group of tag defined in a model.
func GetTags ¶
func GetTags(field reflect.StructField, args ...TagsAnalyzerOption) Tags
GetTags returns field tags.
func (*Tags) Set ¶
func (tags *Tags) Set(name string, property TagProperty)
Set sets the given tag into the slice.
type TagsAnalyzerOption ¶
type TagsAnalyzerOption func(*TagsAnalyzerOptions)
TagsAnalyzerOption is a functional option to configure TagsAnalyzerOptions.
type TagsAnalyzerOptions ¶
type TagsAnalyzerOptions struct {
// Name defines the default tag name.
Name string
// Collector defines what tags should be analyzed.
Collector []string
// NameMapper defines how to convert a supported tag to the default one.
NameMapper map[string]string
// KeyMapper defines how to convert a tag key tag to another one (aliasing).
KeyMapper map[string]string
}
TagsAnalyzerOptions defines the tags analyzer behavior.
