sqlboiler: github.com/vattle/sqlboiler/bdb Index | Files | Directories

package bdb

import "github.com/vattle/sqlboiler/bdb"

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

Index

Package Files

column.go interface.go keys.go relationships.go table.go

func ColumnDBTypes Uses

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

ColumnDBTypes of the columns.

func ColumnNames Uses

func ColumnNames(cols []Column) []string

ColumnNames of the columns.

type Column Uses

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 Uses

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

FilterColumnsByAuto generates the list of columns that have autogenerated values

func FilterColumnsByDefault Uses

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

FilterColumnsByDefault generates the list of columns that have default values

func FilterColumnsByEnum Uses

func FilterColumnsByEnum(columns []Column) []Column

FilterColumnsByEnum generates the list of columns that are enum values.

type ForeignKey Uses

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 Uses

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 Uses

type PrimaryKey struct {
    Name    string
    Columns []string
}

PrimaryKey represents a primary key constraint in a database

type SQLColumnDef Uses

type SQLColumnDef struct {
    Name string
    Type string
}

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

func (SQLColumnDef) String Uses

func (s SQLColumnDef) String() string

String for fmt.Stringer

type SQLColumnDefs Uses

type SQLColumnDefs []SQLColumnDef

SQLColumnDefs has small helper functions

func SQLColDefinitions Uses

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

SQLColDefinitions creates a definition in sql format for a column

func (SQLColumnDefs) Names Uses

func (s SQLColumnDefs) Names() []string

Names returns all the names

func (SQLColumnDefs) Types Uses

func (s SQLColumnDefs) Types() []string

Types returns all the types

type Table Uses

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 Uses

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

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

func Tables Uses

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 Uses

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 Uses

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

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

type ToManyRelationship Uses

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 Uses

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

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

type ToOneRelationship Uses

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 Uses

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

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

Directories

PathSynopsis
drivers

Package bdb imports 5 packages (graph) and is imported by 22 packages. Updated 2018-06-27. Refresh now. Tools for package owners. This is a quick bug-fix fork (has fewer than three commits, and only during the week it was created).