dibbi

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2023 License: AGPL-3.0 Imports: 9 Imported by: 0

README

🐳 dibbi

Build

In-memory non-persistent relational database.

Examples

Create Table

CREATE TABLE users
(
  age  int,
  name text
);

Insert

INSERT INTO users
VALUES (24, 'Alessio');

Select

SELECT age
from users;

Select All

SELECT *
from users;

Run

go run main.go

Test

go test -v ./...

Features

  • SELECT
  • CREATE TABLE
    • int
    • text
    • bool
  • INSERT
  • SELECT * to get all Columns

TODO

  • Insert with column specification
  • WHERE clause
  • More column types (uuid, date)
  • Automatic uuid on insertion, if specified during CREATE TABLE
  • default values
  • Support float

Resources

Documentation

Overview

Package dibbi contains functions to manipulate a dibbi instance.

Index

Constants

View Source
const (
	SelectType astType = iota
	CreateTableType
	InsertType
)
View Source
const (
	SelectKeyword     keyword = "select"
	FromKeyword       keyword = "from"
	AsKeyword         keyword = "as"
	TableKeyword      keyword = "table"
	CreateKeyword     keyword = "create"
	InsertKeyword     keyword = "insert"
	IntoKeyword       keyword = "into"
	ValuesKeyword     keyword = "values"
	IntKeyword        keyword = "int"
	TextKeyword       keyword = "text"
	BoolKeyword       keyword = "bool"
	WhereKeyword      keyword = "where"
	AndKeyword        keyword = "and"
	OrKeyword         keyword = "or"
	TrueKeyword       keyword = "true"
	FalseKeyword      keyword = "false"
	UniqueKeyword     keyword = "unique"
	IndexKeyword      keyword = "index"
	OnKeyword         keyword = "on"
	PrimaryKeyKeyword keyword = "primary key"
	NullKeyword       keyword = "null"
	LimitKeyword      keyword = "limit"
	OffsetKeyword     keyword = "offset"
	DropKeyword       keyword = "drop"

	SemicolonSymbol        symbol = ";"
	AsteriskSymbol         symbol = "*"
	CommaSymbol            symbol = ","
	LeftParenthesesSymbol  symbol = "("
	RightParenthesesSymbol symbol = ")"
	EqualsSymbol           symbol = "="
	NeqSymbol              symbol = "<>"
	NeqSymbol2             symbol = "!="
	ConcatSymbol           symbol = "||"
	PlusSymbol             symbol = "+"
	LtSymbol               symbol = "<"
	LteSymbol              symbol = "<="
	GtSymbol               symbol = ">"
	GteSymbol              symbol = ">="

	KeywordType tokenType = iota
	SymbolType
	IdentifierType
	StringType
	NumericType
	BooleanType
	NullType
)

Variables

View Source
var (
	ErrTableDoesNotExist  = errors.New("table does not exist")
	ErrColumnDoesNotExist = errors.New("column does not exist")
	ErrInvalidSelectItem  = errors.New("select item is not valid")
	ErrInvalidDatatype    = errors.New("invalid datatype")
	ErrMissingValues      = errors.New("missing values")
)

Functions

func Lex

func Lex(source string) ([]*token, error)

Types

type Cell

type Cell interface {
	AsText() *string
	AsInt() *int32
	AsBool() *bool
}

type ColumnType

type ColumnType uint

ColumnType defines the available column types

const (
	TextType ColumnType = iota
	IntType
	BoolType
)

func (ColumnType) String

func (c ColumnType) String() string

type Cursor

type Cursor struct {
	Pointer uint
	// contains filtered or unexported fields
}

type Database

type Database interface {
	CreateTable(*createTableStatement) error
	//DropTable(*dropTableStatement) error
	//CreateIndex(*createIndexStatement) error
	Insert(*InsertStatement) error
	Select(*selectStatement) (*Results, error)
}

type ExpressionType

type ExpressionType uint
const (
	LiteralType ExpressionType = iota
)

func (ExpressionType) String

func (lt ExpressionType) String() string

type InMemoryBackend

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

func NewMemoryBackend

func NewMemoryBackend() *InMemoryBackend

func (*InMemoryBackend) CreateTable

func (mb *InMemoryBackend) CreateTable(crt *createTableStatement) error

func (*InMemoryBackend) Insert

func (mb *InMemoryBackend) Insert(inst *InsertStatement) error

func (*InMemoryBackend) Select

func (mb *InMemoryBackend) Select(selectStatement *selectStatement) (*Results, error)

type Index

type Index struct {
	Name       string
	Exp        string
	Type       string
	Unique     bool
	PrimaryKey bool
}

type InsertStatement

type InsertStatement struct {
	Table  token
	Values *[]*expression
}

func (*InsertStatement) String

func (s *InsertStatement) String() string

type ResultColumn

type ResultColumn struct {
	Type    ColumnType
	Name    string
	NotNull bool
}

type Results

type Results struct {
	Columns []ResultColumn
	Rows    [][]Cell
}

func Query

func Query(query string, db *Database) (result *Results, isResultPresent bool, error error)

Query the database with the given input.

type TableMetadata

type TableMetadata struct {
	Name    string
	Columns []ResultColumn
	Indexes []Index
}

Jump to

Keyboard shortcuts

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