Documentation
¶
Index ¶
- func Drop(ctx context.Context, dbc DB, schemasuffix string) error
- func Exists(ctx context.Context, dbc DB, schemasuffix string) (bool, error)
- func SchemaName(suffix string) string
- func SchemaSuffixFromHash(doc sqldocument.Document) string
- type Batch
- type DB
- type Deployable
- func (d Deployable) CodePatch(dbc *sql.DB, sql string) string
- func (d Deployable) DropAndUpload(ctx context.Context, dbc DB) error
- func (d *Deployable) EnsureUploaded(ctx context.Context, dbc DB) error
- func (d Deployable) IntConst(s string) (int, error)
- func (d *Deployable) IsUploadedFromCache(dbc DB) bool
- func (d *Deployable) ListUploaded(ctx context.Context, dbc DB) ([]*SchemaObject, error)
- func (d Deployable) MustIntConst(s string) int
- func (d Deployable) Patch(sql string) string
- func (d *Deployable) Upload(ctx context.Context, dbc DB) error
- func (d Deployable) WithSchemaSuffix(schemaSuffix string) Deployable
- type MSSQLUserError
- type Options
- type PreprocessedFile
- type PreprocessorError
- type SQLCodeParseErrors
- type SchemaObject
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SchemaName ¶
func SchemaSuffixFromHash ¶
func SchemaSuffixFromHash(doc sqldocument.Document) string
Types ¶
type Batch ¶
type Batch struct {
StartPos sqldocument.Pos
Lines string
// contains filtered or unexported fields
}
func (Batch) LineNumberInInput ¶
LineNumberInInput transforms an error line number when executing the batch, into an absolute line number in StartPos.File
func (Batch) RelativeLineNumberInInput ¶
RelativeLineNumberInInput maps a line number from the output of preprocessing (`outputline)` to a line number in the input of the pre-processing. PS: StartPos must be considered *in addition* to this transform.
type DB ¶
type DB interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
Conn(ctx context.Context) (*sql.Conn, error)
BeginTx(ctx context.Context, txOptions *sql.TxOptions) (*sql.Tx, error)
Driver() driver.Driver
}
type Deployable ¶
type Deployable struct {
SchemaSuffix string
ParsedFiles []string // mainly for use in error messages etc
CodeBase sqldocument.Document
// contains filtered or unexported fields
}
func Include ¶
func Include(opts Options, fsys ...fs.FS) (result Deployable, err error)
Include is used to package SQL code included using the `embed` go feature; constructing a Deployable of SQL code. Currently, only a single packageName is supported, but we can make string e.g. `...string` later.
func MustInclude ¶
func MustInclude(opts Options, fsys ...fs.FS) Deployable
func (Deployable) CodePatch ¶
func (d Deployable) CodePatch(dbc *sql.DB, sql string) string
CodePatch will preprocess the sql passed in to call the correct SQL code deployed to the provided database. Q: Nameing? DBPatch, PatchV2, ???
func (Deployable) DropAndUpload ¶
func (d Deployable) DropAndUpload(ctx context.Context, dbc DB) error
UploadWithOverwrite will always drop the schema if it exists, before uploading. This is suitable for named schema suffixes.
func (*Deployable) EnsureUploaded ¶
func (d *Deployable) EnsureUploaded(ctx context.Context, dbc DB) error
EnsureUploaded checks that the schema with the suffix already exists, and if not, creates and uploads it. This is suitable for hash-based schema suffixes. A lock will be taken (globally in SQL) during the process so that multiple concurrent calls from services starting at the same time line up nicely
func (Deployable) IntConst ¶
func (d Deployable) IntConst(s string) (int, error)
TODO: StringConst. This requires parsing a SQL literal, a bit too complex to code up just-in-case
func (*Deployable) IsUploadedFromCache ¶
func (d *Deployable) IsUploadedFromCache(dbc DB) bool
func (*Deployable) ListUploaded ¶
func (d *Deployable) ListUploaded(ctx context.Context, dbc DB) ([]*SchemaObject, error)
Return a list of sqlcode schemas that have been uploaded to the database. This includes all current and unused schemas.
func (Deployable) MustIntConst ¶
func (d Deployable) MustIntConst(s string) int
func (Deployable) Patch ¶
func (d Deployable) Patch(sql string) string
Patch will preprocess the sql passed in so that it will call SQL code deployed by the receiver Deployable for SQL Server. NOTE: This will be deprecated and eventually replaced with CodePatch.
func (*Deployable) Upload ¶
func (d *Deployable) Upload(ctx context.Context, dbc DB) error
Upload will create and upload the schema; resulting in an error if the schema already exists
func (Deployable) WithSchemaSuffix ¶
func (d Deployable) WithSchemaSuffix(schemaSuffix string) Deployable
type MSSQLUserError ¶
func (MSSQLUserError) Error ¶
func (s MSSQLUserError) Error() string
type Options ¶
type Options struct {
IncludeTags []string
// if this is set, parsing or ordering failed and it's up to the caller
// to know what one is doing..
PartialParseResults bool
}
Options that affect file parsing etc; pass an empty struct to get default options.
type PreprocessedFile ¶
type PreprocessedFile struct {
Batches []Batch
}
func Preprocess ¶
func Preprocess(doc sqldocument.Document, schemasuffix string, driver driver.Driver) (PreprocessedFile, error)
type PreprocessorError ¶
type PreprocessorError struct {
Pos sqldocument.Pos
Message string
}
func (PreprocessorError) Error ¶
func (p PreprocessorError) Error() string
type SQLCodeParseErrors ¶
type SQLCodeParseErrors struct {
Errors []sqldocument.Error
}
func (SQLCodeParseErrors) Error ¶
func (e SQLCodeParseErrors) Error() string
Directories
¶
| Path | Synopsis |
|---|---|
|
Simple non-performant recursive descent parser for purposes of sqlcode; currently only supports the special @Enum declarations used by sqlcode.
|
Simple non-performant recursive descent parser for purposes of sqlcode; currently only supports the special @Enum declarations used by sqlcode. |