dbkit

package
v0.0.0-...-9e9b37c Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func NullableBool

func NullableBool(value bool) *bool

NullableBool returns a pointer to the given value, and is useful for inline values to methods that require pointer values for nullable columns. E.g., table.Insert(dbkit.NullableBool(false))

func NullableInt32

func NullableInt32(value int32) *int32

NullableInt32 returns a pointer to the given value, and is useful for inline values to methods that require pointer values for nullable columns. E.g., table.Insert(dbkit.NullableInt32(345))

func NullableInt64

func NullableInt64(value int64) *int64

NullableInt64 returns a pointer to the given value, and is useful for inline values to methods that require pointer values for nullable columns. E.g., table.Insert(dbkit.NullableInt64(345))

func NullableString

func NullableString(value string) *string

NullableString returns a pointer to the given value, and is useful for inline values to methods that require pointer values for nullable columns. E.g., table.Insert(dbkit.NullableString("somevalue"))

func NullableTime

func NullableTime(value time.Time) *time.Time

NullableTime returns a pointer to the given value, and is useful for inline values to methods that require pointer values for nullable columns. E.g., table.Insert(dbkit.NullableTime(time.Now()))

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

Types

type Cassandra

type Cassandra struct {
	// contains filtered or unexported fields
}

func OpenCassandra

func OpenCassandra(u *url.URL) (*Cassandra, error)

func (*Cassandra) GetSchema

func (c *Cassandra) GetSchema(packageName string, log func(msg string, args ...interface{})) (*Schema, error)

type CockroachDBBatch

type CockroachDBBatch interface {
	ExecuteCockroachDB(ctx context.Context, noUpdateConflict bool, returningNothing bool) error
}

type Column

type Column struct {
	DBName      string
	GoName      string
	GoLowerName string
	Type        DataType
	Nullable    bool
}

Column represents a column in a database table

func (*Column) GoType

func (c *Column) GoType() string

GoType returns the go typename as a string

func (*Column) IsArray

func (c *Column) IsArray() bool

type DataType

type DataType int

DataType represents the various data types allowed for table columns

const (
	// DataTypeAutoID maps to an auto increment id or closest matching construct in the database. A table can only have one AutoID columns and it must be the only column in the primary key.
	DataTypeAutoID DataType = iota
	// DataTypeInt64 is a 64bit integer value
	DataTypeInt64
	// DataTypeInt32 is a 32bit integer value
	DataTypeInt32
	// DataTypeFloat64 is a 64bit floating-point number
	DataTypeFloat64
	// DataTypeString is a string value
	DataTypeString
	// DataTypeTime is a time value (date+time)
	DataTypeTime
	// DataTypeDate is a date value (date)
	DataTypeDate
	// DataTypeBytes is a bytes value ([]byte)
	DataTypeBytes
	// DataTypeBool is a boolean value
	DataTypeBool
	// DataTypeTimeUUID is a TimeUUID value
	DataTypeTimeUUID
	// DataTypeTimeUUID is a UUID value
	DataTypeUUID
	// DataTypeJSON is a JSON value
	DataTypeJSON
	// DataTypeStringArray is a string array
	DataTypeStringArray
)

type Direction

type Direction int

Direction represents a sort order for a query (ascending or descending)

const (
	// Ascending specifies ascending sort order ("order by <col> asc")
	Ascending Direction = iota
	// Descending specifies descending sort order ("order by <col> desc")
	Descending
)

type ExtraField

type ExtraField struct {
	Name       string
	GoTypeName string
	Import     string
}

ExtraField represents an extra go field added to the generated struct for a given table

type Index

type Index struct {
	IsPrimary bool
	Name      string
	Columns   []*Column
	Table     *Table
}

Index represents an index in a database table

func (*Index) LoaderKeyFromStruct

func (i *Index) LoaderKeyFromStruct(variable string) string

func (*Index) LoaderKeyFuncArgs

func (i *Index) LoaderKeyFuncArgs() string

func (*Index) LoaderKeyFuncValue

func (i *Index) LoaderKeyFuncValue() string

func (*Index) LoaderKeyGoType

func (i *Index) LoaderKeyGoType() string

func (*Index) LoaderKeyUnpack

func (i *Index) LoaderKeyUnpack(variable string) string

type IndexCombination

type IndexCombination struct {
	Name     string
	FuncArgs string
	CallArgs string
	Columns  []*Column
	Table    Table
}

IndexCombination is a column combinations suitable for index lookup.

type Postgres

type Postgres struct {
	// contains filtered or unexported fields
}

func OpenPostgres

func OpenPostgres(u *url.URL) (*Postgres, error)

func (*Postgres) GetSchema

func (p *Postgres) GetSchema(packageName string, log func(msg string, args ...interface{})) (*Schema, error)

type Schema

type Schema struct {
	PackageName string
	Tables      map[string]*Table
}

Schema represents a database schema

func NewSchema

func NewSchema(packageName string) *Schema

NewSchema creates a new schema

func (*Schema) Generate

func (s *Schema) Generate(dir string, logging bool, generatorNames ...string) []error

Generate generates table and driver files for the schema

func (*Schema) LoaderImports

func (s *Schema) LoaderImports() map[string]bool

func (*Schema) NewTable

func (s *Schema) NewTable(dbTableName string, goTableName string, structName string) *Table

NewTable creates a new table in the schema

func (*Schema) ReadExtraFieldsFile

func (s *Schema) ReadExtraFieldsFile(filename string, log func(msg string, args ...interface{})) error

func (*Schema) SortedTables

func (s *Schema) SortedTables() []*Table

func (*Schema) Validate

func (s *Schema) Validate(generators []generator) []error

Validate returns a list of validation errors from the schema

type Table

type Table struct {
	DBTableName string

	GoTableName      string
	GoLowerTableName string

	StructName      string
	LowerStructName string
	Columns         []*Column
	ExtraFields     []*ExtraField
	Indexes         map[string]*Index
	PrimaryIndex    *Index

	Logging bool
}

Table represents a table in a database schema

func (*Table) AddColumn

func (t *Table) AddColumn(dbName string, goName string, dataType DataType, nullable bool)

AddColumn adds a colum to the table

func (*Table) AddIndex

func (t *Table) AddIndex(name string, columns ...string) *Index

AddIndex adds the index to the table

func (*Table) AutoIDColumn

func (t *Table) AutoIDColumn() *Column

AutoIDColumn returns the AutoID column of the table (if any)

func (*Table) GetColumn

func (t *Table) GetColumn(name string) *Column

GetColumn gets the specified column

func (*Table) IndexCombinations

func (t *Table) IndexCombinations() []*IndexCombination

IndexCombinations builds a list of column combinations suitable for index lookups.

func (*Table) NonAutoIDColumns

func (t *Table) NonAutoIDColumns() []*Column

NonAutoIDColumns builds a slice of columns that aren't of type AutoID

func (*Table) SetPrimaryIndex

func (t *Table) SetPrimaryIndex(columns ...string)

SetPrimaryIndex sets the primary index on the table

func (*Table) Validate

func (t *Table) Validate(generators []generator) []error

Validate returns a list of validation errors from the table

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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