bdb

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2016 License: BSD-3-Clause Imports: 4 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
}

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

func FilterColumnsByDefault

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

FilterColumnsByDefault generates the list of columns that have default 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(exclude []string) ([]string, error)
	Columns(tableName string) ([]Column, error)
	PrimaryKeyInfo(tableName string) (*PrimaryKey, error)
	ForeignKeyInfo(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

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

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
	Columns []Column

	PKey  *PrimaryKey
	FKeys []ForeignKey

	IsJoinTable bool

	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, exclude ...string) ([]Table, error)

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

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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