bdb

package
v2.4.0+incompatible Latest Latest
Warning

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

Go to latest
Published: May 9, 2017 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package bdb supplies the sql(b)oiler (d)ata(b)ase abstractions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColumnDBTypes

func ColumnDBTypes(cols []Column) map[string]string

ColumnDBTypes of the columns.

func ColumnNames

func ColumnNames(cols []Column) []string

ColumnNames of the columns.

Types

type Column

type Column struct {
	Name      string
	Type      string
	DBType    string
	Default   string
	Nullable  bool
	Unique    bool
	Validated bool

	// Postgres only extension bits
	// ArrType is the underlying data type of the Postgres
	// ARRAY type. See here:
	// https://www.postgresql.org/docs/9.1/static/infoschema-element-types.html
	ArrType *string
	UDTName string

	// MySQL only bits
	// Used to get full type, ex:
	// tinyint(1) instead of tinyint
	// Used for "tinyint-as-bool" flag
	FullDBType string

	// MS SQL only bits
	// Used to indicate that the value
	// for this column is auto generated by database on insert (i.e. - timestamp (old) or rowversion (new))
	AutoGenerated bool
}

Column holds information about a database column. Types are Go types, converted by TranslateColumnType.

func FilterColumnsByAuto

func FilterColumnsByAuto(auto bool, columns []Column) []Column

FilterColumnsByAuto generates the list of columns that have autogenerated values

func FilterColumnsByDefault

func FilterColumnsByDefault(defaults bool, columns []Column) []Column

FilterColumnsByDefault generates the list of columns that have default values

func FilterColumnsByEnum

func FilterColumnsByEnum(columns []Column) []Column

FilterColumnsByEnum generates the list of columns that are enum values.

type ForeignKey

type ForeignKey struct {
	Table    string
	Name     string
	Column   string
	Nullable bool
	Unique   bool

	ForeignTable          string
	ForeignColumn         string
	ForeignColumnNullable bool
	ForeignColumnUnique   bool
}

ForeignKey represents a foreign key constraint in a database

type Interface

type Interface interface {
	TableNames(schema string, whitelist, blacklist []string) ([]string, error)
	Columns(schema, tableName string) ([]Column, error)
	PrimaryKeyInfo(schema, tableName string) (*PrimaryKey, error)
	ForeignKeyInfo(schema, tableName string) ([]ForeignKey, error)

	// TranslateColumnType takes a Database column type and returns a go column type.
	TranslateColumnType(Column) Column

	// UseLastInsertID should return true if the driver is capable of using
	// the sql.Exec result's LastInsertId
	UseLastInsertID() bool

	// UseTopClause should return true if the Database is capable of using
	// the SQL TOP clause
	UseTopClause() bool

	// Open the database connection
	Open() error
	// Close the database connection
	Close()

	// Dialect helpers, these provide the values that will go into
	// a queries.Dialect, so the query builder knows how to support
	// your database driver properly.
	LeftQuote() byte
	RightQuote() byte
	IndexPlaceholders() bool
}

Interface for a database driver. Functionality required to support a specific database type (eg, MySQL, Postgres etc.)

type PrimaryKey

type PrimaryKey struct {
	Name    string
	Columns []string
}

PrimaryKey represents a primary key constraint in a database

type SQLColumnDef

type SQLColumnDef struct {
	Name string
	Type string
}

SQLColumnDef formats a column name and type like an SQL column definition.

func (SQLColumnDef) String

func (s SQLColumnDef) String() string

String for fmt.Stringer

type SQLColumnDefs

type SQLColumnDefs []SQLColumnDef

SQLColumnDefs has small helper functions

func SQLColDefinitions

func SQLColDefinitions(cols []Column, names []string) SQLColumnDefs

SQLColDefinitions creates a definition in sql format for a column

func (SQLColumnDefs) Names

func (s SQLColumnDefs) Names() []string

Names returns all the names

func (SQLColumnDefs) Types

func (s SQLColumnDefs) Types() []string

Types returns all the types

type Table

type Table struct {
	Name string
	// For dbs with real schemas, like Postgres.
	// Example value: "schema_name"."table_name"
	SchemaName string
	Columns    []Column

	PKey  *PrimaryKey
	FKeys []ForeignKey

	IsJoinTable bool

	ToOneRelationships  []ToOneRelationship
	ToManyRelationships []ToManyRelationship
}

Table metadata from the database schema.

func GetTable

func GetTable(tables []Table, name string) (tbl Table)

GetTable by name. Panics if not found (for use in templates mostly).

func Tables

func Tables(db Interface, schema string, whitelist, blacklist []string) ([]Table, error)

Tables returns the metadata for all tables, minus the tables specified in the blacklist.

func (Table) CanLastInsertID

func (t Table) CanLastInsertID() bool

CanLastInsertID checks the following: 1. Is there only one primary key? 2. Does the primary key column have a default value? 3. Is the primary key column type one of uintX/intX? If the above is all true, this table can use LastInsertId

func (Table) GetColumn

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

GetColumn by name. Panics if not found (for use in templates mostly).

type ToManyRelationship

type ToManyRelationship struct {
	Table    string
	Column   string
	Nullable bool
	Unique   bool

	ForeignTable          string
	ForeignColumn         string
	ForeignColumnNullable bool
	ForeignColumnUnique   bool

	ToJoinTable bool
	JoinTable   string

	JoinLocalColumn         string
	JoinLocalColumnNullable bool
	JoinLocalColumnUnique   bool

	JoinForeignColumn         string
	JoinForeignColumnNullable bool
	JoinForeignColumnUnique   bool
}

ToManyRelationship describes a relationship between two tables where the local table has no id, and the foreign table has an id that matches a column in the local table.

func ToManyRelationships

func ToManyRelationships(table string, tables []Table) []ToManyRelationship

ToManyRelationships relationship lookups Input should be the sql name of a table like: videos

type ToOneRelationship

type ToOneRelationship struct {
	Table    string
	Column   string
	Nullable bool
	Unique   bool

	ForeignTable          string
	ForeignColumn         string
	ForeignColumnNullable bool
	ForeignColumnUnique   bool
}

ToOneRelationship describes a relationship between two tables where the local table has no id, and the foregin table has an id that matches a column in the local table, that column is also unique which changes the dynamic into a one-to-one style, not a to-many.

func ToOneRelationships

func ToOneRelationships(table string, tables []Table) []ToOneRelationship

ToOneRelationships relationship lookups Input should be the sql name of a table like: videos

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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