db

package
v0.0.0-...-b11c152 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2020 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Package db provides an abstract database interface for Go.

types.go2:1

Example
package main

import (
	"fmt"

	"qlova.store/db"
)

type UserViewer struct {
	db.View `db:"users"`

	ID db.UUID `db:",key"`

	Name db.String
}

func main() {
	var User UserViewer

	defer db.Open().Connect(&User).Close()

	db.Sync(User)

	var bob = User
	bob.Name.Set("Bob")

	db.Insert(bob)

	var user = User
	db.If(user.Name.Equals("Bob")).Get(&user)

	fmt.Println(user.Name)

}
Output:

Bob

Index

Examples

Constants

This section is empty.

Variables

View Source
var False = Condition{Operator: OpFalse}
View Source
var True = Condition{}

Functions

func Connect

func Connect(viewer Viewer, driver Driver) error

Connect initialises and connects the given viewer.

func Delete

func Delete(table Viewer, tables ...Viewer) error

Delete removes the viewer's table from the database. The master viewer must be passed to this function.

func Empty

func Empty(table Viewer, tables ...Viewer) error

Empty removes all rows from the given tables so that they are empty.

func Insert

func Insert(first Row, rows ...Row) error

Insert inserts the given rows into their registered databases.

func Sync

func Sync(table Table, tables ...Table) error

Sync syncs the Tables with the Database, adding any missing columns. If constraints or types do not match up, an error is returned.

func Tokenise

func Tokenise(text string) (words []string)

Types

type Bool

type Bool struct {
	// contains filtered or unexported fields
}

types.go2:13

func (Bool) Column

func (t Bool) Column() string

func (Bool) Database

func (t Bool) Database() Driver

func (Bool) Decreasing

func (t Bool) Decreasing() Sorter

func (Bool) Equals

func (t Bool) Equals(val bool,

) Condition

func (Bool) FieldName

func (t Bool) FieldName() string

func (Bool) Increasing

func (t Bool) Increasing() Sorter

func (*Bool) Index

func (t *Bool) Index(index int) bool

func (Bool) Interface

func (t Bool) Interface() interface{}

func (Bool) Key

func (t Bool) Key() bool

func (*Bool) Make

func (t *Bool) Make(length int) interface{}

func (Bool) MarshalJSON

func (t Bool) MarshalJSON() ([]byte, error)

func (*Bool) Master

func (t *Bool) Master() bool

func (Bool) NotEquals

func (t Bool) NotEquals(val bool,

) Condition

func (Bool) Offset

func (t Bool) Offset() uintptr

func (Bool) On

func (t Bool) On(other struct{ instantiate୦୦Type୦bool }) Linker

func (*Bool) Pointer

func (t *Bool) Pointer() interface{}

func (*Bool) Set

func (t *Bool) Set(val bool,

)

func (*Bool) Slice

func (t *Bool) Slice(index int) interface{}

func (Bool) String

func (t Bool) String() string

func (Bool) Table

func (t Bool) Table() string

func (Bool) Test

func (t Bool) Test(ctx *testing.T)

types.go2:198

func (Bool) To

func (t Bool) To(val bool,

) Update

func (Bool) Type

func (t Bool) Type() reflect.Type

func (Bool) Value

func (t Bool) Value() bool

type Builtin

type Builtin string

Builtin is a builtin database.

func (Builtin) Close

func (Builtin) Close() error

Close closes the connection to the database.

func (Builtin) Connect

func (b Builtin) Connect(first Viewer, more ...Viewer) Driver

Connect connects the given viewer to view this database. It then returns the database.

func (Builtin) Delete

func (b Builtin) Delete(table Table, tables ...Table) error

Delete deletes the given tables.

func (Builtin) Empty

func (b Builtin) Empty(table Table, tables ...Table) error

Empty removes all rows from the given tables so that they are empty.

func (Builtin) Insert

func (b Builtin) Insert(row Row, rows ...Row) error

Insert inserts the given row into the database.

func (Builtin) Search

func (b Builtin) Search(f Filter) Results

Search with the given filter and return the results.

func (Builtin) Sync

func (b Builtin) Sync(table Table, tables ...Table) error

Sync syncs the Tables with the Database, adding any missing columns. If constraints or types do not match up, an error is returned.

type Bytes

type Bytes struct {
	// contains filtered or unexported fields
}

types.go2:13

func (Bytes) Column

func (t Bytes) Column() string

func (Bytes) Database

func (t Bytes) Database() Driver

func (Bytes) Decreasing

func (t Bytes) Decreasing() Sorter

func (Bytes) Equals

func (t Bytes) Equals(val []byte,

) Condition

func (Bytes) FieldName

func (t Bytes) FieldName() string

func (Bytes) Increasing

func (t Bytes) Increasing() Sorter

func (*Bytes) Index

func (t *Bytes) Index(index int) bool

func (Bytes) Interface

func (t Bytes) Interface() interface{}

func (Bytes) Key

func (t Bytes) Key() bool

func (*Bytes) Make

func (t *Bytes) Make(length int) interface{}

func (Bytes) MarshalJSON

func (t Bytes) MarshalJSON() ([]byte, error)

func (*Bytes) Master

func (t *Bytes) Master() bool

func (Bytes) NotEquals

func (t Bytes) NotEquals(val []byte,

) Condition

func (Bytes) Offset

func (t Bytes) Offset() uintptr

func (Bytes) On

func (t Bytes) On(other struct {
	// types.go2:189
	instantiate୦୦Type୦୮6୮7byte
}) Linker

func (*Bytes) Pointer

func (t *Bytes) Pointer() interface{}

func (*Bytes) Set

func (t *Bytes) Set(val []byte,

)

func (*Bytes) Slice

func (t *Bytes) Slice(index int) interface{}

func (Bytes) String

func (t Bytes) String() string

func (Bytes) Table

func (t Bytes) Table() string

func (Bytes) Test

func (t Bytes) Test(ctx *testing.T)

types.go2:198

func (Bytes) To

func (t Bytes) To(val []byte,

) Update

func (Bytes) Type

func (t Bytes) Type() reflect.Type

func (Bytes) Value

func (t Bytes) Value() []byte

type Column

type Column interface {
	Column() string
	Database() Driver
	Type() reflect.Type
	Offset() uintptr
	Key() bool
}

Column is the definition of a column.

type Condition

type Condition struct {
	Table, Column string
	Operator
	Value interface{}

	View Table

	//If any of the cases match, this condition evaluates to true.
	Cases []Condition

	Invert bool
	// contains filtered or unexported fields
}

Condition can be used to specify a filter.

func Both

func Both(a, b Condition) Condition

Both returns a condition that is true if all of it's arguments are true.

func Either

func Either(a, b Condition) Condition

Either returns a condition that is true if either of it's arguments are true.

func Switch

func Switch(first Condition, cases ...Condition) Condition

Switch returns a condition that is true if any of it's case conditions are true.

type Dictionary

type Dictionary interface {

	//IndexWords returns related concept-indicies for the given words.
	//The indicies should be constant (for a given word within a given dictionary)
	//and unique to the concept that the word represents.
	//prime multiples can represent sub-concepts, ie animal = 3, dog = 6.
	//prime combinations can represent intersecting concepts.
	//meaningless words should be set to 1.
	//words that are used at a higher frequency should return lower numbers.
	//Words without dictionary entries should return 0.
	LookupWords(results []int64, words ...string) error
}

Dictionary is required for efficient natural-language search. How you setup/store the dictionary is up to you. But DictionaryMap & DictionaryViewer implementations are provided by this package.

type DictionaryMap

type DictionaryMap struct {
	sync.RWMutex

	Map map[string]int64

	NextPrime int64
}

DictionaryMap implements a map-backed Dictionary.

func NewDictionary

func NewDictionary() *DictionaryMap

NewDictionary returns a new DictionaryMap.

func (*DictionaryMap) Add

func (d *DictionaryMap) Add(words ...string)

Add adds a word to the dictionary.

func (*DictionaryMap) AddSynonym

func (d *DictionaryMap) AddSynonym(synonym string, of string)

AddSynonym adds a synonym to the dictionary.

func (*DictionaryMap) LookupWords

func (d *DictionaryMap) LookupWords(results []int64, words ...string) error

LookupWords implements Dictionary.LookupWords

type Driver

type Driver interface {
	//Connect connects the given viewers to view this database.
	//It then returns the database.
	Connect(Viewer, ...Viewer) Driver

	//Sync syncs the Tables with the Database, adding any missing columns.
	//If constraints or types do not match up, an error is returned.
	Sync(Table, ...Table) error

	//Insert inserts the given row into the database.
	Insert(Row, ...Row) error

	//Delete deletes the given tables.
	Delete(Table, ...Table) error

	//Empty removes all rows from the given tables so that they are empty.
	Empty(Table, ...Table) error

	//Search returns results for the given filter.
	Search(Filter) Results

	//Close closes the connection to the database.
	Close() error
}

Driver is a database driver.

func Open

func Open(args ...string) Driver

Open opens a database based on the provided optional arguments. The first argument is a database name and subsequent arguments are passed to it. If no arguments are provided, a builtin database is used.

type Error

type Error string

Error is a database error.

const ErrDisconnectedViewer Error = "disconnected viewer"

ErrDisconnectedViewer means that an disconnected viewer was used, connect the viewer to a database to resolve this error.

const ErrDuplicateKey Error = "duplicate key"

ErrDuplicateKey means that a value tried to be inserted into the database but it failed due to having a duplicate value.

const ErrIllegalMaster Error = "illegal use of master viewer"

ErrIllegalMaster means that an attempt was made to write to a master viewer, assign the viewer to a variable to resolve this error.

const ErrMasterProtected Error = "this operation must be performed on a master viewer"

ErrMasterProtected means that an attempt was made to peform an operation on a clone of master. The operation was blocked for data-protection purposes. If you meant to perform this operation, pass a master viewer.

const ErrNotFound Error = "row not found"

ErrNotFound is returned if no row is found when getting from the database.

const ErrTableNotFound Error = "table not found"

ErrTableNotFound means that the operation failed because the viewer's table was not found. Check that the name of the table is correct, or create it with Sync()

const ErrUnregisteredViewer Error = "unregistered viewer"

ErrUnregisteredViewer means that an unregistered viewer was used, register the viewer to resolve this error.

func (Error) Error

func (err Error) Error() string

type Expression

type Expression struct {
	Table, Column string
	Operator
	Value interface{}

	View Table
	// contains filtered or unexported fields
}

Expression containing a column.

type Filter

type Filter struct {
	Table string
	View  Table

	Condition  Condition
	Conditions []Condition

	Sort  Sorter
	Sorts []Sorter

	Link  Linker
	Links []Linker

	Offset, Length int

	Columns []Variable
	// contains filtered or unexported fields
}

Filter describes which rows to select in a database.

func If

func If(condition Condition, conditions ...Condition) Filter

If returns a filter on the database with the given conditions.

func Link(linker Linker, linkers ...Linker) Filter

Link returns a filter with the given links applied.

func (Filter) Average

func (f Filter) Average(v Viewable) (float64, error)

Average sets the variable to the average value of all results of that column.

func (Filter) Count

func (f Filter) Count(v Viewable) (int, error)

Count counts the number of results.

func (Filter) Delete

func (f Filter) Delete() (int, error)

Delete deletes all the results from the database.

func (Filter) Get

func (f Filter) Get(v Viewer) error

Get moves the filter's selection into the given viewer.

func (Filter) If

func (f Filter) If(condition Condition, conditions ...Condition) Filter

If returns a filter on the database with the additional conditions.

func (Filter) MarshalJSON

func (f Filter) MarshalJSON() ([]byte, error)

MarshalJSON encodes the results of the filter into JSON.

func (Filter) Read

func (f Filter) Read(v Variable, vs ...Variable) error

Read reads into the given variables.

func (Filter) Slice

func (f Filter) Slice(offset, length int, columns ...Variable) Slicer

Slice selects the slice of the results that this filter should return.

func (Filter) SortBy

func (f Filter) SortBy(sorter Sorter, sorters ...Sorter) Filter

SortBy sorts on the results of the filter with the given sorters.

func (Filter) Sum

func (f Filter) Sum(v Variable) error

Sum sets the variable to the sum of all results of that column.

func (Filter) Update

func (f Filter) Update(update Update, updates ...Update) (int, error)

Update updates the selected items with the given updates. Returns the number of items updated (or -1 if the statistic is unavailable).

type Float32

type Float32 struct {
	// contains filtered or unexported fields
}

types.go2:13

func (Float32) Column

func (t Float32) Column() string

func (Float32) Database

func (t Float32) Database() Driver

func (Float32) Decreasing

func (t Float32) Decreasing() Sorter

func (Float32) Equals

func (t Float32) Equals(val float64,

) Condition

func (Float32) FieldName

func (t Float32) FieldName() string

func (Float32) Increasing

func (t Float32) Increasing() Sorter

func (*Float32) Index

func (t *Float32) Index(index int) bool

func (Float32) Interface

func (t Float32) Interface() interface{}

func (Float32) Key

func (t Float32) Key() bool

func (*Float32) Make

func (t *Float32) Make(length int) interface{}

func (Float32) MarshalJSON

func (t Float32) MarshalJSON() ([]byte, error)

func (*Float32) Master

func (t *Float32) Master() bool

func (Float32) NotEquals

func (t Float32) NotEquals(val float64,

) Condition

func (Float32) Offset

func (t Float32) Offset() uintptr

func (Float32) On

func (t Float32) On(other struct {
	// types.go2:189
	instantiate୦୦Type୦float64
}) Linker

func (*Float32) Pointer

func (t *Float32) Pointer() interface{}

func (*Float32) Set

func (t *Float32) Set(val float64,

)

func (*Float32) Slice

func (t *Float32) Slice(index int) interface{}

func (Float32) String

func (t Float32) String() string

func (Float32) Table

func (t Float32) Table() string

func (Float32) Test

func (t Float32) Test(ctx *testing.T)

types.go2:198

func (Float32) To

func (t Float32) To(val float64,

) Update

func (Float32) Type

func (t Float32) Type() reflect.Type

func (Float32) Value

func (t Float32) Value() float64

type Float64

type Float64 struct {
	// contains filtered or unexported fields
}

types.go2:13

func (Float64) Column

func (t Float64) Column() string

func (Float64) Database

func (t Float64) Database() Driver

func (Float64) Decreasing

func (t Float64) Decreasing() Sorter

func (Float64) Equals

func (t Float64) Equals(val float64,

) Condition

func (Float64) FieldName

func (t Float64) FieldName() string

func (Float64) Increasing

func (t Float64) Increasing() Sorter

func (*Float64) Index

func (t *Float64) Index(index int) bool

func (Float64) Interface

func (t Float64) Interface() interface{}

func (Float64) Key

func (t Float64) Key() bool

func (*Float64) Make

func (t *Float64) Make(length int) interface{}

func (Float64) MarshalJSON

func (t Float64) MarshalJSON() ([]byte, error)

func (*Float64) Master

func (t *Float64) Master() bool

func (Float64) NotEquals

func (t Float64) NotEquals(val float64,

) Condition

func (Float64) Offset

func (t Float64) Offset() uintptr

func (Float64) On

func (t Float64) On(other struct {
	// types.go2:189
	instantiate୦୦Type୦float64
}) Linker

func (*Float64) Pointer

func (t *Float64) Pointer() interface{}

func (*Float64) Set

func (t *Float64) Set(val float64,

)

func (*Float64) Slice

func (t *Float64) Slice(index int) interface{}

func (Float64) String

func (t Float64) String() string

func (Float64) Table

func (t Float64) Table() string

func (Float64) Test

func (t Float64) Test(ctx *testing.T)

types.go2:198

func (Float64) To

func (t Float64) To(val float64,

) Update

func (Float64) Type

func (t Float64) Type() reflect.Type

func (Float64) Value

func (t Float64) Value() float64

type Importable୦

type Importable୦ int

types.go2:242

type Insertion

type Insertion struct {
	Table
	Columns []string
	Uniques []bool
	Values  []interface{}
}

Insertion describes an insertion operation into the database.

func (*Insertion) Row

func (insert *Insertion) Row(row Row) error

Row makes the insetion operation insert the given row.

type Int16

type Int16 struct {
	// contains filtered or unexported fields
}

types.go2:13

func (Int16) Column

func (t Int16) Column() string

func (Int16) Database

func (t Int16) Database() Driver

func (Int16) Decreasing

func (t Int16) Decreasing() Sorter

func (Int16) Equals

func (t Int16) Equals(val int16,

) Condition

func (Int16) FieldName

func (t Int16) FieldName() string

func (Int16) Increasing

func (t Int16) Increasing() Sorter

func (*Int16) Index

func (t *Int16) Index(index int) bool

func (Int16) Interface

func (t Int16) Interface() interface{}

func (Int16) Key

func (t Int16) Key() bool

func (*Int16) Make

func (t *Int16) Make(length int) interface{}

func (Int16) MarshalJSON

func (t Int16) MarshalJSON() ([]byte, error)

func (*Int16) Master

func (t *Int16) Master() bool

func (Int16) NotEquals

func (t Int16) NotEquals(val int16,

) Condition

func (Int16) Offset

func (t Int16) Offset() uintptr

func (Int16) On

func (t Int16) On(other struct{ instantiate୦୦Type୦int16 }) Linker

func (*Int16) Pointer

func (t *Int16) Pointer() interface{}

func (*Int16) Set

func (t *Int16) Set(val int16,

)

func (*Int16) Slice

func (t *Int16) Slice(index int) interface{}

func (Int16) String

func (t Int16) String() string

func (Int16) Table

func (t Int16) Table() string

func (Int16) Test

func (t Int16) Test(ctx *testing.T)

types.go2:198

func (Int16) To

func (t Int16) To(val int16,

) Update

func (Int16) Type

func (t Int16) Type() reflect.Type

func (Int16) Value

func (t Int16) Value() int16

type Int32

type Int32 struct {
	// contains filtered or unexported fields
}

types.go2:13

func (Int32) Column

func (t Int32) Column() string

func (Int32) Database

func (t Int32) Database() Driver

func (Int32) Decreasing

func (t Int32) Decreasing() Sorter

func (Int32) Equals

func (t Int32) Equals(val int32,

) Condition

func (Int32) FieldName

func (t Int32) FieldName() string

func (Int32) Increasing

func (t Int32) Increasing() Sorter

func (*Int32) Index

func (t *Int32) Index(index int) bool

func (Int32) Interface

func (t Int32) Interface() interface{}

func (Int32) Key

func (t Int32) Key() bool

func (*Int32) Make

func (t *Int32) Make(length int) interface{}

func (Int32) MarshalJSON

func (t Int32) MarshalJSON() ([]byte, error)

func (*Int32) Master

func (t *Int32) Master() bool

func (Int32) NotEquals

func (t Int32) NotEquals(val int32,

) Condition

func (Int32) Offset

func (t Int32) Offset() uintptr

func (Int32) On

func (t Int32) On(other struct{ instantiate୦୦Type୦int32 }) Linker

func (*Int32) Pointer

func (t *Int32) Pointer() interface{}

func (*Int32) Set

func (t *Int32) Set(val int32,

)

func (*Int32) Slice

func (t *Int32) Slice(index int) interface{}

func (Int32) String

func (t Int32) String() string

func (Int32) Table

func (t Int32) Table() string

func (Int32) Test

func (t Int32) Test(ctx *testing.T)

types.go2:198

func (Int32) To

func (t Int32) To(val int32,

) Update

func (Int32) Type

func (t Int32) Type() reflect.Type

func (Int32) Value

func (t Int32) Value() int32

type Int64

type Int64 struct {
	// contains filtered or unexported fields
}

types.go2:13

func (Int64) Column

func (t Int64) Column() string

func (Int64) Database

func (t Int64) Database() Driver

func (Int64) Decreasing

func (t Int64) Decreasing() Sorter

func (Int64) DivisibleBy

func (i Int64) DivisibleBy(val int64) Condition

DivisibleBy returns a condition that is true if i is divisible by val.

func (Int64) Equals

func (t Int64) Equals(val int64,

) Condition

func (Int64) FieldName

func (t Int64) FieldName() string

func (Int64) Increasing

func (t Int64) Increasing() Sorter

func (*Int64) Index

func (t *Int64) Index(index int) bool

func (Int64) Interface

func (t Int64) Interface() interface{}

func (Int64) Key

func (t Int64) Key() bool

func (Int64) LessThan

func (i Int64) LessThan(val int64) Condition

LessThan returns a condition that is true if i is less then val.

func (*Int64) Make

func (t *Int64) Make(length int) interface{}

func (Int64) MarshalJSON

func (t Int64) MarshalJSON() ([]byte, error)

func (*Int64) Master

func (t *Int64) Master() bool

func (Int64) NotEquals

func (t Int64) NotEquals(val int64,

) Condition

func (Int64) Offset

func (t Int64) Offset() uintptr

func (Int64) On

func (t Int64) On(other struct{ instantiate୦୦Type୦int64 }) Linker

func (*Int64) Pointer

func (t *Int64) Pointer() interface{}

func (*Int64) Set

func (t *Int64) Set(val int64,

)

func (*Int64) Slice

func (t *Int64) Slice(index int) interface{}

func (Int64) String

func (t Int64) String() string

func (Int64) Table

func (t Int64) Table() string

func (Int64) Test

func (t Int64) Test(ctx *testing.T)

types.go2:198

func (Int64) To

func (t Int64) To(val int64,

) Update

func (Int64) Type

func (t Int64) Type() reflect.Type

func (Int64) Value

func (t Int64) Value() int64

type Int8

type Int8 struct {
	// contains filtered or unexported fields
}

types.go2:13

func (Int8) Column

func (t Int8) Column() string

func (Int8) Database

func (t Int8) Database() Driver

func (Int8) Decreasing

func (t Int8) Decreasing() Sorter

func (Int8) Equals

func (t Int8) Equals(val int8,

) Condition

func (Int8) FieldName

func (t Int8) FieldName() string

func (Int8) Increasing

func (t Int8) Increasing() Sorter

func (*Int8) Index

func (t *Int8) Index(index int) bool

func (Int8) Interface

func (t Int8) Interface() interface{}

func (Int8) Key

func (t Int8) Key() bool

func (*Int8) Make

func (t *Int8) Make(length int) interface{}

func (Int8) MarshalJSON

func (t Int8) MarshalJSON() ([]byte, error)

func (*Int8) Master

func (t *Int8) Master() bool

func (Int8) NotEquals

func (t Int8) NotEquals(val int8,

) Condition

func (Int8) Offset

func (t Int8) Offset() uintptr

func (Int8) On

func (t Int8) On(other struct{ instantiate୦୦Type୦int8 }) Linker

func (*Int8) Pointer

func (t *Int8) Pointer() interface{}

func (*Int8) Set

func (t *Int8) Set(val int8,

)

func (*Int8) Slice

func (t *Int8) Slice(index int) interface{}

func (Int8) String

func (t Int8) String() string

func (Int8) Table

func (t Int8) Table() string

func (Int8) Test

func (t Int8) Test(ctx *testing.T)

types.go2:198

func (Int8) To

func (t Int8) To(val int8,

) Update

func (Int8) Type

func (t Int8) Type() reflect.Type

func (Int8) Value

func (t Int8) Value() int8

type Iterator

type Iterator struct {
	Viewer
	Index int
}

func Range

func Range(viewer Viewer) *Iterator

Range returns a new iterator.

func (*Iterator) Next

func (r *Iterator) Next() bool

Next loads viewer's next result into the viewer. Returns false when there are no more results.

type LinkablesViewer

type LinkablesViewer struct {
	View `db:"linkable"`

	ID    Int64 `db:",key"`
	Value String
}

LinkablesViewer can be used to view the 'linkable' table.

type Linker

type Linker struct {
	From, To Viewable

	View Table
}

Linker links two tables together so that they can be searched on.

type Operator

type Operator int

Operator type in a condition.

const (
	OpTrue Operator = iota
	OpFalse
	OpEquals
	OpContains
	OpNotEquals
	OpHasPrefix
	OpLessThan
	OpDivisibleBy
)

Operators

type Results

type Results interface {
	json.Marshaler

	//Update updates the results with the given updates.
	//Returns the number of results updated (or -1 if the statistic is unavailable).
	Update(Update, ...Update) (int, error)

	//Delete deletes all the results from the database.
	Delete() (int, error)

	//Get gets the matching columns of the results.
	Get(Variable, ...Variable) (int, error)

	//Count returns the number of results.
	Count(Viewable) (int, error)

	//Sum returns the sum amount of the value in the given column of all results.
	Sum(Variable) error

	//Average returns the average value in the given column for all results.
	Average(Viewable) (float64, error)
}

Results of a searchfilter.

type Row

type Row interface {
	Row() Table
}

Row can return its table definition.

type Rune

type Rune = Int32

types.go2:13

type Slicer

type Slicer Filter

Slicer is returned by Filter.Slice

func (Slicer) Into

func (s Slicer) Into(v Viewer) (int, error)

Into moves the filter's selection into the given viewer.

func (Slicer) MarshalJSON

func (s Slicer) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (Slicer) Read

func (s Slicer) Read() (int, error)

Read reads into the given variables.

type Sorter

type Sorter struct {
	Table      string
	Column     string
	Decreasing bool
}

Sorter defines how to sort a given column.

type String

type String struct {
	// contains filtered or unexported fields
}

types.go2:13

func (String) Column

func (t String) Column() string

func (String) Contains

func (s String) Contains(val string) Condition

Contains returns a condition that is true if s contains val.

func (String) Database

func (t String) Database() Driver

func (String) Decreasing

func (t String) Decreasing() Sorter

func (String) Equals

func (t String) Equals(val string,

) Condition

func (String) FieldName

func (t String) FieldName() string

func (String) HasPrefix

func (s String) HasPrefix(val string) Condition

HasPrefix returns a condition that is true if s starts with val.

func (String) Increasing

func (t String) Increasing() Sorter

func (*String) Index

func (t *String) Index(index int) bool

func (String) Interface

func (t String) Interface() interface{}

func (String) Key

func (t String) Key() bool

func (*String) Make

func (t *String) Make(length int) interface{}

func (String) MarshalJSON

func (t String) MarshalJSON() ([]byte, error)

func (*String) Master

func (t *String) Master() bool

func (String) NotEquals

func (t String) NotEquals(val string,

) Condition

func (String) Offset

func (t String) Offset() uintptr

func (String) On

func (t String) On(other struct{ instantiate୦୦Type୦string }) Linker

func (*String) Pointer

func (t *String) Pointer() interface{}

func (*String) Set

func (t *String) Set(val string,

)

func (*String) Slice

func (t *String) Slice(index int) interface{}

func (String) String

func (t String) String() string

func (String) Table

func (t String) Table() string

func (String) Test

func (t String) Test(ctx *testing.T)

types.go2:198

func (String) To

func (t String) To(val string,

) Update

func (String) Type

func (t String) Type() reflect.Type

func (String) Value

func (t String) Value() string

type Table

type Table interface {
	Table() string

	Columns() int
	Column(i int) Column

	Database() Driver
}

Table is a database table definition.

type TestSuite

type TestSuite struct {
	test.Suite

	Driver

	Testable TestablesViewer
	Linkable LinkablesViewer
}

TestSuite that can be applied to drivers to test for consistency. It uses the 'testable' table and as long as this table is not in use, the tests are isolated from the rest of the database. If the test passes, then there will be no trace of the test-data in the database. This makes it safe to use on databases that are in use.

func (*TestSuite) SetupSuite

func (ts *TestSuite) SetupSuite()

SetupSuite gets called before any of the tests are run. Connecting the test tables.

func (*TestSuite) TestConnect

func (ts *TestSuite) TestConnect()

TestConnect tests the driver view-connection functionality.

func (*TestSuite) TestDelete

func (ts *TestSuite) TestDelete()

TestDelete tests that the driver is able to delete a table.

func (*TestSuite) TestEmpty

func (ts *TestSuite) TestEmpty()

TestEmpty tests that the driver is able to empty a table.

func (*TestSuite) TestInsert

func (ts *TestSuite) TestInsert()

TestInsert tests that the driver is able to insert records into the database.

func (ts *TestSuite) TestLink()

TestLink tests that the driver can link two tables together for filtering.

func (*TestSuite) TestPrimaryKey

func (ts *TestSuite) TestPrimaryKey()

TestPrimaryKey tests that the driver will reject duplicate values for a given primary key.

func (*TestSuite) TestResultsAverage

func (ts *TestSuite) TestResultsAverage()

TestResultsAverage tests the result average function.

func (*TestSuite) TestResultsCount

func (ts *TestSuite) TestResultsCount()

TestResultsCount tests the results counting function.

func (*TestSuite) TestResultsDelete

func (ts *TestSuite) TestResultsDelete()

TestResultsDelete tests the deletion of rows.

func (*TestSuite) TestResultsGet

func (ts *TestSuite) TestResultsGet()

TestResultsGet tests the retrieval of rows.

func (*TestSuite) TestResultsJSON

func (ts *TestSuite) TestResultsJSON()

TestResultsJSON tests the json marshalling of rows.

func (*TestSuite) TestResultsNotFound

func (ts *TestSuite) TestResultsNotFound()

TestResultsNotFound tests that ErrNotFound is returned if a record does not exist.

func (*TestSuite) TestResultsRead

func (ts *TestSuite) TestResultsRead()

TestResultsRead tests the retrieval of given columns.

func (*TestSuite) TestResultsSlice

func (ts *TestSuite) TestResultsSlice()

TestResultsSlice tests filter slicing.

func (*TestSuite) TestResultsSum

func (ts *TestSuite) TestResultsSum()

TestResultsSum tests the result sum function.

func (*TestSuite) TestResultsUpdate

func (ts *TestSuite) TestResultsUpdate()

TestResultsUpdate tests the updating of rows.

func (*TestSuite) TestSync

func (ts *TestSuite) TestSync()

TestSync tests that the driver is able to sync the Testable table.

func (*TestSuite) TestTypes

func (ts *TestSuite) TestTypes()

TestTypes tests the db types.

type TestablesViewer

type TestablesViewer struct {
	View `db:"testable"`

	ID    Int64 `db:",key"`
	Value String
}

TestablesViewer can be used to view the 'testable' table.

type Text

type Text struct {
	String

	//WordIndex is used to speed up search.
	WordIndex Int64

	//Dictionary used for indexing.
	Dictionary Dictionary
}

Text is searchable text.

func (Text) Column

func (t Text) Column() string

func (Text) Database

func (t Text) Database() Driver

func (Text) Decreasing

func (t Text) Decreasing() Sorter

func (Text) Equals

func (t Text) Equals(val string,

) Condition

func (Text) FieldName

func (t Text) FieldName() string

func (*Text) Has

func (t *Text) Has(word string) Condition

Has does a word search on the text.

func (Text) Increasing

func (t Text) Increasing() Sorter

func (*Text) Index

func (t *Text) Index(index int) bool

func (Text) Interface

func (t Text) Interface() interface{}

func (Text) Key

func (t Text) Key() bool

func (*Text) Make

func (t *Text) Make(length int) interface{}

func (Text) MarshalJSON

func (t Text) MarshalJSON() ([]byte, error)

func (*Text) Master

func (t *Text) Master() bool

func (Text) NotEquals

func (t Text) NotEquals(val string,

) Condition

func (Text) Offset

func (t Text) Offset() uintptr

func (Text) On

func (t Text) On(other struct{ instantiate୦୦Type୦string }) Linker

func (*Text) Pointer

func (t *Text) Pointer() interface{}

func (*Text) Search

func (t *Text) Search(query string) Condition

Search does a search checking if the tokens in the query string are also found in the text.

func (*Text) Set

func (t *Text) Set(to string)

Set text to the given string.

func (*Text) Slice

func (t *Text) Slice(index int) interface{}

func (Text) String

func (t Text) String() string

func (Text) Table

func (t Text) Table() string

func (Text) Test

func (t Text) Test(ctx *testing.T)

types.go2:198

func (*Text) To

func (t *Text) To(new string) Update

func (Text) Type

func (t Text) Type() reflect.Type

func (Text) Value

func (t Text) Value() string

type Time

type Time struct {
	// contains filtered or unexported fields
}

types.go2:13

func (Time) Column

func (t Time) Column() string

func (Time) Database

func (t Time) Database() Driver

func (Time) Decreasing

func (t Time) Decreasing() Sorter

func (Time) Equals

func (t Time) Equals(val time.Time,

) Condition

func (Time) FieldName

func (t Time) FieldName() string

func (Time) Increasing

func (t Time) Increasing() Sorter

func (*Time) Index

func (t *Time) Index(index int) bool

func (Time) Interface

func (t Time) Interface() interface{}

func (Time) Key

func (t Time) Key() bool

func (*Time) Make

func (t *Time) Make(length int) interface{}

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

func (*Time) Master

func (t *Time) Master() bool

func (Time) NotEquals

func (t Time) NotEquals(val time.Time,

) Condition

func (Time) Offset

func (t Time) Offset() uintptr

func (Time) On

func (t Time) On(other struct {
	// types.go2:189
	instantiate୦୦Type୦time୮aTime
}) Linker

func (*Time) Pointer

func (t *Time) Pointer() interface{}

func (*Time) Set

func (t *Time) Set(val time.Time,

)

func (*Time) Slice

func (t *Time) Slice(index int) interface{}

func (Time) String

func (t Time) String() string

func (Time) Table

func (t Time) Table() string

func (Time) Test

func (t Time) Test(ctx *testing.T)

types.go2:198

func (Time) To

func (t Time) To(val time.Time,

) Update

func (Time) Type

func (t Time) Type() reflect.Type

func (Time) Value

func (t Time) Value() time.Time

type UUID

type UUID struct {
	// contains filtered or unexported fields
}

types.go2:13

func (UUID) Column

func (t UUID) Column() string

func (UUID) Database

func (t UUID) Database() Driver

func (UUID) Decreasing

func (t UUID) Decreasing() Sorter

func (UUID) Equals

func (t UUID) Equals(val uid,

) Condition

func (UUID) FieldName

func (t UUID) FieldName() string

func (UUID) Increasing

func (t UUID) Increasing() Sorter

func (*UUID) Index

func (t *UUID) Index(index int) bool

func (UUID) Interface

func (t UUID) Interface() interface{}

func (UUID) Key

func (t UUID) Key() bool

func (*UUID) Make

func (t *UUID) Make(length int) interface{}

func (UUID) MarshalJSON

func (t UUID) MarshalJSON() ([]byte, error)

func (*UUID) Master

func (t *UUID) Master() bool

func (UUID) NotEquals

func (t UUID) NotEquals(val uid,

) Condition

func (UUID) Offset

func (t UUID) Offset() uintptr

func (UUID) On

func (t UUID) On(other struct {
	// types.go2:189
	instantiate୦୦Type୦db୮auid
}) Linker

func (*UUID) Pointer

func (t *UUID) Pointer() interface{}

func (*UUID) Set

func (t *UUID) Set(val uid,

)

func (*UUID) Slice

func (t *UUID) Slice(index int) interface{}

func (UUID) String

func (t UUID) String() string

func (UUID) Table

func (t UUID) Table() string

func (UUID) Test

func (t UUID) Test(ctx *testing.T)

types.go2:198

func (UUID) To

func (t UUID) To(val uid,

) Update

func (UUID) Type

func (t UUID) Type() reflect.Type

func (UUID) Value

func (t UUID) Value() uid

type Update

type Update struct {
	Column, Table string
	Value         interface{}

	Then *Update
	// contains filtered or unexported fields
}

Update describes a modification to make to a row in the database.

func (Update) And

func (u Update) And(other Update) Update

func (Update) Database

func (u Update) Database() Driver

Database returns the Driver of this update.

type Variable

type Variable interface {
	Viewable

	Pointer() interface{}

	Make(int) interface{}

	Index(int) bool
	Slice(int) interface{}

	Master() bool
}

Variable is a variable value in the database.

func Mutate

func Mutate(v Viewer, column Column) Variable

Mutate allows a column inside of a viewer to be modified.

type View

type View struct {
	// contains filtered or unexported fields
}

View is a type that implements Viewer & Row. Embed this in your models and tag it with the name of the table you would like to view. ie `db:"users"`

func (View) Column

func (v View) Column(i int) Column

Column implements Table.

func (View) Columns

func (v View) Columns() int

Columns implements Table.

func (View) Database

func (v View) Database() Driver

Database implements Table.

func (*View) Master

func (v *View) Master() bool

Master implements Viewer.

func (View) Row

func (v View) Row() Table

Row implements Row.

func (*View) SetDriver

func (v *View) SetDriver(database Driver)

SetDriver implements Viewer.

func (*View) SetWindow

func (v *View) SetWindow(length int)

SetWindow sets the length of elements to view.

func (View) Setup

func (v View) Setup() bool

Setup returns true if this viewer is setup and ready to use.

func (View) Table

func (v View) Table() string

Table implements Table.

type Viewable

type Viewable interface {
	Column

	Interface() interface{}
	Table() string
}

Viewable is a value in the database that can be viewed.

func LookAt

func LookAt(row Row, column Column) Viewable

LookAt allows a column inside of a row to be viewed.

type Viewer

type Viewer interface {
	Table

	SetDriver(database Driver)

	Setup() bool
	Master() bool
	// contains filtered or unexported methods
}

Viewer is any type that is viewing a table of a specific database. Embed a View type to implement Viewer.

Directories

Path Synopsis
driver

Jump to

Keyboard shortcuts

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