schema

package
v0.0.0-...-fad6b96 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package schema provide a general interface to obtain schema information from a database

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column interface {
	Namer
	Index() int
	Type() string
	// GoType should be the equivalent go type
	GoType() interface{}
	// IsPrimary return true if the column is part of the Primary Key, with int being the index. Otherwise, bool will be false, and int will be -1
	IsPrimary() (bool, int)
	Nullable() bool
	Default() (interface{}, error)
	Hidden() bool
}

Column describes a Column in a table

type Database

type Database interface {
	Databaser
	Namer

	// Schemata returns all the schema's in the database
	Schemata() ([]Schema, error)
	// SchemaName is the name of the default schema
	SchemaName() string
	// Schema interface functions other then Name should be for the default schema.
	Schema
}

Database describes a generic database, an database provider could have additional functions

type Databaser

type Databaser interface {
	Database() *sql.DB
}

type ForeignKey

type ForeignKey interface {
	// ID is the ForeignKey ID
	ID() int
	// Seq is the seq id for multi-key references. Will always start at Zero
	Seq() int
	FromTable() string
	ToTable() string
	FromColumn() string
	ToColumn() string
	OnUpdate() string
	OnDelete() string
	Match() string
}

type Index

type Index interface {
	Namer
	Table() string
	Columns() ([]Column, error)
}

type NamedSQLer

type NamedSQLer interface {
	Namer
	SQLer
}

type Namer

type Namer interface {
	Name() string
}

type NullColumns

type NullColumns struct{}

func (NullColumns) Columns

func (col NullColumns) Columns() ([]Column, error)

type NullDatabase

type NullDatabase struct {
}

NullDatabase can be embedded into another Struct to get some basic functions to satisfy the Database interface

func (NullDatabase) SchemaName

func (db NullDatabase) SchemaName() string

func (NullDatabase) Schemata

func (db NullDatabase) Schemata() ([]Schema, error)

type NullForeignKey

type NullForeignKey struct{}

func (NullForeignKey) ID

func (ForeignKey NullForeignKey) ID() int

func (NullForeignKey) Match

func (foreignKey NullForeignKey) Match() string

func (NullForeignKey) OnDelete

func (foreignKey NullForeignKey) OnDelete() string

func (NullForeignKey) OnUpdate

func (foreignKey NullForeignKey) OnUpdate() string

type NullForeignKeys

type NullForeignKeys struct{}

func (NullForeignKeys) ForeignKeys

func (foreignKeys NullForeignKeys) ForeignKeys() ([]ForeignKey, error)

type NullSchema

type NullSchema struct{}

NullSchema can be embedded into another Struct to get some basic functions to satisfy the Schema interface

func (NullSchema) Indexes

func (schema NullSchema) Indexes() ([]Index, error)

func (NullSchema) Tables

func (schema NullSchema) Tables() ([]Table, error)

func (NullSchema) Triggers

func (schema NullSchema) Triggers() ([]Trigger, error)

func (NullSchema) Views

func (schema NullSchema) Views() ([]View, error)

type NullTable

type NullTable struct {
	NullColumns
	NullForeignKeys
}

type SQLer

type SQLer interface {
	// SQL to create the object
	SQL() string
}

type Schema

type Schema interface {
	Namer
	// Tables returns the tables in the schema
	Tables() ([]Table, error)
	// Views returns the views in the schema
	Views() ([]View, error)
	Indexes() ([]Index, error)
	Triggers() ([]Trigger, error)
}

Schema contains the tables, views, triggers and indexes of the database

type Table

type Table interface {
	NamedSQLer
	// Columns in the table
	Columns() ([]Column, error)
	// Temporary table or not
	Temporary() bool
	ForeignKeys() ([]ForeignKey, error)
	// Triggers on this table
	Triggers() ([]Trigger, error)
	Indexes() ([]Index, error)
}

Table describes a table in the database

type Trigger

type Trigger interface {
	NamedSQLer
	Table() string
}

type View

type View interface {
	NamedSQLer
	Columns() ([]Column, error)
}

Directories

Path Synopsis
internal
Package sqlite provides the schema interface for an SQLite database.
Package sqlite provides the schema interface for an SQLite database.

Jump to

Keyboard shortcuts

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