backend

package
v0.0.0-...-c3ef3ee Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTableAlreadyExists occures when creating table exists
	ErrTableAlreadyExists = errors.New("the table already exists")

	// ErrTableNotFound occures when creating table exists
	ErrTableNotFound = errors.New("there is no such table")

	// ErrIndexNotFound occurs when a table doesn't contain given column.
	ErrIndexNotFound = errors.New("there is no index corresponding column name")
)

Functions

This section is empty.

Types

type ColNameIndexes

type ColNameIndexes map[core.ColumnName]int

ColNameIndexes is map ColName to corresponding column index

func (ColNameIndexes) Copy

func (c ColNameIndexes) Copy() ColNameIndexes

Copy copies ColNameIndexes

type ColumnID

type ColumnID int

ColumnID is type of column id (index of column).

type DB

type DB interface {
	GetTable(string) (Table, error)
	CreateTable(string, core.Cols) error
	DropTable(string) error
}

DB is interface of DBMS

type DBRow

type DBRow struct {
	ColNames core.ColumnNames
	Values   core.Values
}

DBRow is struct of row of table

func (*DBRow) Copy

func (r *DBRow) Copy() *DBRow

Copy copies DBRow

func (*DBRow) GetColNames

func (r *DBRow) GetColNames() core.ColumnNames

GetColNames gets column names from DBRow

func (*DBRow) GetValueByColName

func (r *DBRow) GetValueByColName(name core.ColumnName) (core.Value, error)

GetValueByColName gets value from row by ColName

func (*DBRow) GetValues

func (r *DBRow) GetValues() core.Values

GetValues gets values from DBRow

func (*DBRow) UpdateValue

func (r *DBRow) UpdateValue(name core.ColumnName, val core.Value)

UpdateValue updates value by specifing column name

type DBRows

type DBRows []*DBRow

DBRows is list of DBRow

func (DBRows) Copy

func (r DBRows) Copy() DBRows

Copy copies DBRows

type DBTable

type DBTable struct {
	Name     string
	ColNames core.ColumnNames
	Cols     core.Cols
	Rows     DBRows
}

DBTable is struct for DBTable

func (*DBTable) Copy

func (t *DBTable) Copy() Table

Copy copies DBTable

func (*DBTable) CrossJoin

func (t *DBTable) CrossJoin(rtb Table) (Table, error)

CrossJoin took cross join given tables

func (*DBTable) Delete

func (t *DBTable) Delete(condFn func(Row) (core.Value, error)) (Table, error)

func (*DBTable) GetColNames

func (t *DBTable) GetColNames() core.ColumnNames

GetColNames return column names of table

func (*DBTable) GetCols

func (t *DBTable) GetCols() core.Cols

GetCols return column names of table

func (*DBTable) GetName

func (t *DBTable) GetName() string

GetName return table name

func (*DBTable) GetRows

func (t *DBTable) GetRows() []Row

GetRows gets rows from given table

func (*DBTable) InsertValues

func (t *DBTable) InsertValues(names core.ColumnNames, valsList core.ValuesList) error

InsertValues inserts values into the table

func (*DBTable) Limit

func (t *DBTable) Limit(N int) (Table, error)

Limit selects limited number of record

func (*DBTable) OrderBy

func (t *DBTable) OrderBy(cols core.ColumnNames, sortDirs []int) (Table, error)

OrderBy sorts rows by given column names

func (*DBTable) Project

func (t *DBTable) Project(TargetColNames core.ColumnNames, resFuncs []func(Row) (core.Value, error)) (Table, error)

Project is method to select columns of table.

func (*DBTable) RenameTableName

func (t *DBTable) RenameTableName(name string)

RenameTableName updates table name

func (*DBTable) SetColNames

func (t *DBTable) SetColNames(names core.ColumnNames)

SetColNames sets ColNames in Table

func (*DBTable) Update

func (t *DBTable) Update(colNames core.ColumnNames, condFn func(Row) (core.Value, error), assignValFns []func(Row) (core.Value, error)) (Table, error)

Update updates records

func (*DBTable) Where

func (t *DBTable) Where(condFn func(Row) (core.Value, error)) (Table, error)

Where filters rows by given where conditions

type Database

type Database struct {
	Tables map[string]*DBTable
}

Database is struct for Database

func NewDatabase

func NewDatabase() *Database

NewDatabase is constructor of Database

func (*Database) CreateTable

func (db *Database) CreateTable(tableName string, cols core.Cols) error

CreateTable is method to create table

func (*Database) DropTable

func (db *Database) DropTable(tableName string) error

DropTable drop table from DB

func (*Database) GetTable

func (db *Database) GetTable(tableName string) (Table, error)

GetTable gets table from DB

type ErrColumnNotFound

type ErrColumnNotFound int
const (
	ColumnNotFound ErrColumnNotFound = iota
)

type Row

type Row interface {
	// GetValueByColName is used in ColRefNode when getting value
	GetValueByColName(core.ColumnName) (core.Value, error)
	GetValues() core.Values
	GetColNames() core.ColumnNames
	UpdateValue(core.ColumnName, core.Value)
}

Row is interface of row of table.

type Table

type Table interface {
	Copy() Table
	GetName() string
	GetColNames() core.ColumnNames
	GetRows() []Row
	GetCols() core.Cols
	InsertValues(core.ColumnNames, core.ValuesList) error
	RenameTableName(string)
	Project(core.ColumnNames, []func(Row) (core.Value, error)) (Table, error)
	Where(func(Row) (core.Value, error)) (Table, error)
	CrossJoin(Table) (Table, error)
	OrderBy(core.ColumnNames, []int) (Table, error)
	Limit(int) (Table, error)
	Update(core.ColumnNames, func(Row) (core.Value, error), []func(Row) (core.Value, error)) (Table, error)
	Delete(func(Row) (core.Value, error)) (Table, error)
}

Table is interface of table.

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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