sqlgen

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const MaxSQLIdentifier = 64
View Source
const MinSQLIdentifier = 2

Variables

View Source
var ErrIdentifierInvalid = errors.New("Identifier can only contain letters, numbers, and underscore")
View Source
var ErrIdentifierStart = errors.New("Identifier must start with a letter")
View Source
var ErrIdentifierTooLong = fmt.Errorf("Identifier must be at most %d characters", MaxSQLIdentifier)
View Source
var ErrIdentifierTooShort = fmt.Errorf("Identifier must be at least %d characters", MinSQLIdentifier)

Functions

func SQLPlaceholderSet

func SQLPlaceholderSet(count int) string

Generates a placeholder string for N values

func SQLQuote

func SQLQuote(src interface{}) (dst string, err error)

Returns ANSI-SQL quoted strings for a passed type

func SqlDriverToDriverName

func SqlDriverToDriverName(driver driver.Driver) string

The database/sql API doesn't provide a way to get the registry name for a driver from the driver type.

func SqlSprintf

func SqlSprintf(format string, args ...string) string

"Replacement" for fmt.Sprintf when splicing together SQL strings in dangerous ways where standard placeholders won't work, such as table and field names

Types

type MetaTable

type MetaTable struct {
	DriverName string
	FamilyName schema.FamilyName
	TableName  schema.TableName
	Fields     []schema.NamedFieldType
	KeyFields  schema.PrimaryKey
}

func BuildMetaTableFromInput

func BuildMetaTableFromInput(
	driverName string,
	familyName string,
	tableName string,
	fieldNames []string,
	fieldTypes []schema.FieldType,
	keyFields []string,
) (famName schema.FamilyName, tblName schema.TableName, tbl *MetaTable, err error)

func (*MetaTable) AddColumnDDL

func (t *MetaTable) AddColumnDDL(fn schema.FieldName, ft schema.FieldType) (string, error)

XXX: should we validate schema with SQLite first? (yes!)

func (*MetaTable) AsCreateTableDDL

func (t *MetaTable) AsCreateTableDDL() (string, error)

func (*MetaTable) ClearTableDDL

func (t *MetaTable) ClearTableDDL() string

func (*MetaTable) DeleteDML

func (t *MetaTable) DeleteDML(values []interface{}) (string, error)

Returns the DML string for a delete for provided fields with placeholders for all of the key fields in proper order.

func (*MetaTable) DropTableDDL

func (t *MetaTable) DropTableDDL() string

func (*MetaTable) FieldNames

func (t *MetaTable) FieldNames() []schema.FieldName

Returns the names of the fields in this table in order

func (MetaTable) ForDriver

func (t MetaTable) ForDriver(newDriver string) (MetaTable, error)

Return a copy of this table for a new driver

func (*MetaTable) UpsertDML

func (t *MetaTable) UpsertDML(values []interface{}) (string, error)

Returns the DML string for an 'Upsert' for provided values

func (*MetaTable) Validate

func (t *MetaTable) Validate() error

Validates the schema locally and returns an error if there's a problem

Jump to

Keyboard shortcuts

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