Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseMigrationName ¶
ParseMigrationName takes a name like 202009161147_the_initial_schema.sql and returns a time representing 20200916114700 and the text "the_initial_schema".
Types ¶
type Ctx ¶
type Ctx struct { // Dialect determines the SQL dialect to generate the support for. Dialect Dialect // Mod is the target module. Mod token.String // Pkg is the target package within the module. Pkg token.String // Migrations contains all user defined dialect specific raw migration statements. Migrations []*Migration // Repositories refers to all module-local interfaces which must be implemented (each as their own repository). // Note that not all methods have bindings and their implementations is either // omitted, abstract or otherwise stubbed out. This is a full qualified name // like my.company.MyType or my/company.MyType. Repositories []Repository }
A Ctx describes the SQL specific environmental context.
type Dialect ¶
type Dialect string
Dialect determines the kind of sql dialect.
const (
MySQL Dialect = "mysql"
)
type ExecMany ¶
type ExecMany struct { // Slice determines the range/list/count target and determines the index 'i' for the declared // in parameters. Slice token.String // This can be a mixture of // myparam // myparam.field // myparam[i] // myparam.field[i] // ... // i represents the loop index. In []token.String }
ExecMany maps a single input slice (or list) parameter into a repeated prepared sql statement. There may be other non-array input parameters. This is optimized for high load batch inserts. There is no result.
type ExecOne ¶
type ExecOne struct {
In []token.String // may contain dots to select a parameter or a parameter field, so either "myParam" or "myParam.Field"
}
ExecOne maps 0, 1 or many input parameters defined as selectors into a prepared sql statement. There is no result.
type Mapping ¶
type Mapping interface {
// contains filtered or unexported methods
}
Mapping of Prepare and Result
type Method ¶
type Method struct { Name token.String // Name must match an interface method of Repository.Implements Query token.String // Query is a literal (usually with placeholders) to execute or query a result set for. Mapping Mapping // Mapping describes what how the sql prepare and scan generator should work. However, multiple returns are not allowed (special to Go only) }
Method declares a method name, the according query and prepare and map bindings. These only make sense in the given context. The actual types are read from the according ast.Func.
type Migration ¶
A Migration represents a transactional group of sql migration statements. All of them should be applied or none. However due to SQL nature, many engines do not support that well with CREATE/DROP TABLE statements. We have no down/revert migrations, because in practice they don't make much sense and only work in few special cases (usually toy projects):
- for large database (million or even billions of rows) you surely don't want to wait for an alter-table. Use the filesystems snapshot feature for a restore which can revert within a second.
- deleting or updating user-owned entries is never reversible.
- a failed migration cannot be safely undone using a down migration because many databases cannot alter tables within a transaction.
type QueryMany ¶
type QueryMany struct { In []token.String // may contain dots to select a parameter or a parameter field, so either "myParam" or "myParam.Field" Out []token.String // may contain dots to select a field or . for the primitive itself }
ExecMany maps 0, 1 or many input parameters defined as selectors into a prepared sql statement.
The result is a slice of either structs or primitives.
type QueryOne ¶
type QueryOne struct { In []token.String // may contain dots to select a parameter or a parameter field, so either "myParam" or "myParam.Field" Out []token.String // may contain dots to select a field or . for the primitive itself }
ExecOne maps 0, 1 or many input parameters defined as selectors into a prepared sql statement.
The result is either a single struct or a single primitive. The type is determined from the ast.Func.
type Repository ¶
type Repository struct { Implements token.String // full qualified name of the implementing interface. Methods []Method // subset of methods which should be implemented automatically. }
A RepoImplSpec declares a repository and methods with data bindings.