Help us shape the future of Go! Take the 2026 Go Developer Survey

dal

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: May 13, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dal

type Dal struct {
	Connection *sql.DB
	Schema     *Schema
}

Dal manages the connection to and the querying of the database

func NewDal

func NewDal(dbConnection *sql.DB) *Dal

NewDal assigns a new Dal instance to the package global DB

func (*Dal) Connect

func (d *Dal) Connect(dbConnection *sql.DB) (e error)

Connect connects to the database

type Field

type Field struct {
	Name         string
	Type         string
	DefaultValue string
}

Field represents a field on a table

type IQuery

type IQuery interface {
	Query() (*sql.Rows, error)
	Exec() (result sql.Result, e error)
	And() IQuery
	Or() IQuery
	Where(name string, value interface{}) IQuery
	Set(fieldName string, value interface{}) IQuery
	Join(tableName string) IQuery
	OnValue(tableName string, value interface{}) IQuery
	OnField(fieldName string, joinTable string, joinField string) IQuery
	Limit(limit int) IQuery
	Offset(offset int) IQuery
	Order(field string, direction string) IQuery
	ToSQL() string
	GetValues() []interface{}
	SelectJoinField(tableName string, fieldName string, as string) IQuery
}

IQuery outlines the methods on build a sql query and interacting with the database

type ISchema

type ISchema interface {
	Select(tableName string) IQuery
	Update(tableName string) IQuery
	Delete(tableName string) IQuery
	Insert(tableName string) IQuery
	AddTable(name string, fields []string) error
	Table(name string) (t *Table)
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (result *sql.Rows, e error)
	GetTables() map[string]*Table
}

ISchema represents DAL schema methods

type Join

type Join struct {
	Table  *Table
	Fields []JoinField
}

Join represents a join clause

type JoinField

type JoinField struct {
	FieldName string
	Value     interface{}
	JoinTable string
	JoinField string
}

JoinField represents a part of a join clause

type Query

type Query struct {
	Table *Table

	// Filters are the phrases used in the where clause
	Filters []ValueField

	Params []string
	Joins  []Join

	GroupBy     string
	SetFields   []string
	QueryType   string
	ValueFields []ValueField
	Dal         *Dal
	Values      []interface{}
	OrderBy     string
	OrderDir    string
	// SelectJoinFields is a collection of fields included in the list of fields selected
	// Format: `joinedTablePrefix`.`fieldName`
	SelectJoinFields []string
	// contains filtered or unexported fields
}

Query defines a query to be made against the database

func (*Query) And

func (q *Query) And() IQuery

And adds an and conjuction in the where clause

func (*Query) Exec

func (q *Query) Exec() (result sql.Result, e error)

Exec executes a sql statement

func (*Query) GetValues

func (q *Query) GetValues() []interface{}

GetValues returns the values used for the current query

func (*Query) Join

func (q *Query) Join(tableName string) IQuery

Join adds a join clause on to a select statement

func (*Query) Limit

func (q *Query) Limit(limit int) IQuery

Limit adds a limit clause to the query

func (*Query) Offset

func (q *Query) Offset(offset int) IQuery

Offset adds an offset clause to the query

func (*Query) OnField

func (q *Query) OnField(fieldName string, joinTable string, joinField string) IQuery

OnField adds an on clause to the most recent join that joins with the field of another table

func (*Query) OnValue

func (q *Query) OnValue(fieldName string, value interface{}) IQuery

OnValue adds an on clause to the most recent join

func (*Query) Or

func (q *Query) Or() IQuery

Or adds an or conjuction in the where clause

func (*Query) Order

func (q *Query) Order(field string, direction string) IQuery

Order adds an orderBy clause to the query

func (*Query) Query

func (q *Query) Query() (*sql.Rows, error)

Query runs the query

func (*Query) SelectJoinField

func (q *Query) SelectJoinField(joinTable string, joinField string, as string) IQuery

SelectJoinField uses a field from a joined table in the select list

func (*Query) Set

func (q *Query) Set(fieldName string, value interface{}) IQuery

Set sets a value for an insert or update statement

func (*Query) ToSQL

func (q *Query) ToSQL() string

ToSQL returns the generated sql string

func (*Query) Where

func (q *Query) Where(name string, value interface{}) IQuery

Where adds a filter on to the where clause

type Schema

type Schema struct {
	Name    string
	Tables  map[string]*Table
	Aliases map[string]string
	Dal     *Dal
}

Schema is a collection of tables

func NewSchema

func NewSchema(dal *Dal, name string) *Schema

NewSchema defines a new schema

func (*Schema) AddTable

func (s *Schema) AddTable(name string, fields []string) error

AddTable adds a table to the schema

func (*Schema) Count

func (s *Schema) Count(tableName string) IQuery

Count starts a count query

func (*Schema) Delete

func (s *Schema) Delete(tableName string) IQuery

Delete starts a delete query

func (*Schema) Exec

func (s *Schema) Exec(query string, args ...interface{}) (sql.Result, error)

Exec prepares and executes the query

func (*Schema) GetTables

func (s *Schema) GetTables() map[string]*Table

GetTables lists the available tables

func (*Schema) Insert

func (s *Schema) Insert(tableName string) IQuery

Insert starts an insert query

func (*Schema) Query

func (s *Schema) Query(query string, args ...interface{}) (result *sql.Rows, e error)

Query runs sql.Query and returns the results

func (*Schema) Select

func (s *Schema) Select(tableName string) IQuery

Select starts a select statement

func (*Schema) Table

func (s *Schema) Table(name string) (t *Table)

Table gets a table

func (*Schema) Update

func (s *Schema) Update(tableName string) IQuery

Update starts an update query

type Table

type Table struct {
	Name      string
	Fields    map[string]*Field
	Alias     string
	FieldKeys []string
}

Table represents a database table

func NewTable

func NewTable(name string) *Table

NewTable creates a new table object

func (*Table) AddField

func (t *Table) AddField(fieldName string) (e error)

AddField adds a new field to the database object

func (*Table) AddFields

func (t *Table) AddFields(fieldNames []string)

AddFields adds a collection of fields

func (*Table) Field

func (t *Table) Field(fieldName string) *Field

Field gets a field from the table by its name

type ValueField

type ValueField struct {
	Name  string
	Value interface{}
}

ValueField is a name/value pair used to setting data on insert or update queries

Jump to

Keyboard shortcuts

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