furydb

package module
v0.0.1-demo Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2021 License: MIT Imports: 17 Imported by: 0

README

FURY DB

Pure GO lang embedded SQL database made quickly and furiously. For hacks and fun.

Background

On the 29th Dec 2020 to the 31th. For 3 days at the Ninja Software we had a Hackathon and this is my project.

Usage

Test codes in cmd dir

Releases

After the demo and at the moment, I'm planning to slowly to implement features for learning and fun, no guarantee though.

Features

I would like FuryDB to have at least following features (subject to change), so it can at least be used in basic projects.

x = done
p = partially done

  • Table
    • [p] Create
    • Alter
    • Delete
    • Types
      • Boolean
      • Int
      • Float
      • String
      • Time
      • [p] UUID
    • Constraints
      • [p] Primary
      • Foreign key
      • Nullable
      • Default
      • Unique
  • Record
    • [p] Insert
    • Update
    • Delete
    • [p] Select
    • Condition
      • Where
      • Limit
      • Top
      • Offset
      • Distinct
      • Order By
      • And
      • Or
      • In
      • IS NULL
      • Comparison
        • Equal
        • Larger (and equal) than
        • Less (and equal) than
        • Like
      • Group by
    • Left Join other table
    • Aggregate functions
      • Count
      • Sum
      • Min
      • Max
      • Sum
  • Go SQL Driver
    • Open
    • Close
    • Query
      • [p] Basic
      • parameterized query
    • Exec
      • [p] Basic
      • parameterized query

Documentation

Index

Constants

View Source
const (
	VersionMajor int = 0 // database schema change
	VersionMinor int = 1 // bug fixes

	// verbose level, use to aid debug
	// 0 off
	// 1 minimal, lib/info level
	// 2 func level
	// 3 block level
	// 4 loop level
	Verbose int = 1
)

version of furydb

View Source
const (
	OperatorTypeLessThan int = iota
	OperatorTypeLessThanOrEqual
	OperatorTypeMoreThan
	OperatorTypeMoreThanOrEqual
	OperatorTypeEqual
	OperatorTypeNotEqual
)

types of comparisions

Variables

View Source
var (
	ErrTableNotExist            = fmt.Errorf("no such table")
	ErrColumnNotExist           = fmt.Errorf("no such column")
	ErrFieldValueLengthNotMatch = fmt.Errorf("columns and values length not match")
	ErrValueTypeNotBool         = fmt.Errorf("value type not bool")
	ErrValueTypeNotInt          = fmt.Errorf("value type not int")
	ErrValueTypeNotFloat        = fmt.Errorf("value type not float")
	ErrValueTypeNotString       = fmt.Errorf("value type not string")
	ErrValueTypeNotTime         = fmt.Errorf("value type not time")
	ErrValueTypeNotBytes        = fmt.Errorf("value type not bytes")
	ErrValueTypeNotUUID         = fmt.Errorf("value type not uuid")
	ErrValueTypeNotMatch        = fmt.Errorf("value type type not match")
	ErrColumnNotNullable        = fmt.Errorf("column not nullable")
	ErrUnknownColumnType        = fmt.Errorf("unknown column type")
	ErrInvalidUUID              = fmt.Errorf("invalid uuid")
	ErrDataTooBig               = fmt.Errorf("data row too big")
)

various errors

Functions

func UUIDBinToStr

func UUIDBinToStr(uid [16]byte) string

UUIDBinToStr convert uuid binary to string

func UUIDNewV4

func UUIDNewV4() (string, error)

UUIDNewV4 generate random uuid string

func UUIDStrToBin

func UUIDStrToBin(txt string) (uid [16]byte, err error)

UUIDStrToBin convert uuid string to bytes

Types

type Column

type Column struct {
	Name string     // name of the column
	Type ColumnType // column data type

	// anything below is used for holding data
	DataIsNull  bool      // value is null (if column is nullable)
	DataIsValid bool      // value is valid (if column is nullable)
	DataBool    bool      // value in type bool
	DataInt     int64     // value in type int
	DataFloat   float64   // value in type float64
	DataString  string    // value in type string
	DataTime    time.Time // value in type time.Time
	DataBytes   []byte    // value in type []byte
	DataUUID    [16]byte  // value in type uuid
}

Column holds schema of individual column, also can be use to hold data

type ColumnType

type ColumnType int

ColumnType that dictate data type that the column value holds

const (
	ColumnTypeBool   ColumnType = 1
	ColumnTypeInt    ColumnType = 2
	ColumnTypeFloat  ColumnType = 3
	ColumnTypeString ColumnType = 4
	ColumnTypeTime   ColumnType = 5
	ColumnTypeBytes  ColumnType = 6
	ColumnTypeUUID   ColumnType = 7
)

various column types

type Constraint

type Constraint struct {
	Name              string     // name of constraint
	ColumnName        string     // column name for
	Type              ColumnType // what is the type of column
	IsPrimaryKey      bool       // is column primary key
	IsUnique          bool       // is column unique
	IsNotNull         bool       // is column not null
	IsForeignKey      bool       // is this a foreign key?
	ForeignTable      string     // foreign key table
	ForeignColumn     string     // foreign key column
	UseDefaultData    bool       // does it have default value
	DefaultDataBool   bool       // default value in type bool
	DefaultDataInt    int64      // default value in type int64
	DefaultDataFloat  float64    // default value in type float64
	DefaultDataString string     // default value in type string
	DefaultDataTime   string     // default value to use, e.g. now()
	DefaultDataBytes  []byte     // default value in type []byte
	DefaultDataUUID   string     // default value in use, e.g. gen_uuid_v4()
}

Constraint holds table column constraint

type Database

type Database struct {
	Name         string // is just a placeholder
	Folderpath   string
	Tables       []*Table
	VersionMajor int
	VersionMinor int
}

Database holds schema of entire database in self contained unit

func Create

func Create(folderpath string, name string) (*Database, error)

Create new blank database

func Load

func Load(folderpath string) (*Database, error)

Load existing database

func (*Database) Close

func (db *Database) Close() error

Close the database

func (*Database) Save

func (db *Database) Save(folderpath ...string) error

Save the database to filesystem

type FuryConn

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

FuryConn sql connection

func (*FuryConn) Begin

func (c *FuryConn) Begin() (_ driver.Tx, err error)

Begin implements driver.Tx interface, not implemented

func (*FuryConn) Close

func (c *FuryConn) Close() error

Close implements driver.Conn interface, not implemented

func (*FuryConn) Commit

func (c *FuryConn) Commit() error

Commit implements driver.Tx interface, not implemented

func (*FuryConn) Prepare

func (c *FuryConn) Prepare(query string) (driver.Stmt, error)

Prepare implements driver.Conn interface, not implemented

func (*FuryConn) Query

func (c *FuryConn) Query(query string, args []driver.Value) (driver.Rows, error)

Query the database

func (*FuryConn) Rollback

func (c *FuryConn) Rollback() error

Rollback implements driver.Tx interface, not implemented

type FuryDriver

type FuryDriver struct {
}

FuryDriver sql driver

func (*FuryDriver) Open

func (d *FuryDriver) Open(folderPath string) (driver.Conn, error)

Open database

type InsertStatement

type InsertStatement struct {
	FieldsAll bool     // true if using all field(s)
	Fields    []string // or individual field(s)
	Values    []string
	TableName string
}

InsertStatement represents a SQL INSERT statement.

type NullBytes

type NullBytes struct {
	Bytes []byte
	Valid bool
}

NullBytes for nullable bytes

func (*NullBytes) Scan

func (n *NullBytes) Scan(value interface{}) error

Scan implements the Scanner interface

func (*NullBytes) Value

func (n *NullBytes) Value() (driver.Value, error)

Value implements the Valuer interface

type NullUUID

type NullUUID struct {
	UUID  [16]byte
	Valid bool
}

NullUUID for nullable uuid

func (*NullUUID) Scan

func (n *NullUUID) Scan(value interface{}) error

Scan implements the Scanner interface

func (*NullUUID) String

func (n *NullUUID) String() string

String display UUID in string format

func (*NullUUID) Value

func (n *NullUUID) Value() (driver.Value, error)

Value implements the Valuer interface

type OperatorType

type OperatorType int

OperatorType for where comparision

type Parser

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

Parser represents a parser.

func NewParser

func NewParser(r io.Reader) *Parser

NewParser returns a new instance of Parser.

type RawBytes

type RawBytes []byte

RawBytes is a byte slice that holds a reference to memory owned by the database itself. After a Scan into a RawBytes, the slice is only valid until the next call to Next, Scan, or Close.

type Row

type Row struct {
	TableName string    // name of the table row refers to
	Columns   []*Column // holds column data
	Deleted   bool      // if deleted, will be skipped during scan
}

Row holds a single row of table data

type Scanner

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

Scanner represents a lexical scanner.

func NewScanner

func NewScanner(r io.Reader) *Scanner

NewScanner returns a new instance of Scanner.

func (*Scanner) Scan

func (s *Scanner) Scan() (tok Token, lit string)

Scan returns the next token and literal value.

func (*Scanner) ScanValue

func (s *Scanner) ScanValue() (tok Token, lit string)

ScanValue returns the next token and literal value.

type SelectStatement

type SelectStatement struct {
	FieldsAll bool     // true if using all field(s)
	Fields    []string // or individual field(s)
	TableName string
}

SelectStatement represents a SQL SELECT statement.

type Table

type Table struct {
	Name        string
	Columns     []*Column
	Constraints []*Constraint
}

Table holds schema of individual table

type TableCreateResult

type TableCreateResult struct {
}

type TableCreateStatement

type TableCreateStatement struct {
	Columns   []string // of individual column
	Types     []string // of individual column type
	TableName string
}

TableCreateStatement represents a SQL CREATE TABLE statement.

type Token

type Token int

Token represents a lexical token.

const (
	// Special tokens
	ILLEGAL Token = iota
	EOF
	WS

	// Literals
	IDENT // main
	VALUE // sql value; 'bla', 1, 1.23

	// Misc characters
	ASTERISK  // *
	COMMA     // ,
	LEFTPAR   // (
	RIGHTPAR  // )
	SINGLEQUO // '
	DOUBLEQUO // "
	SEMICOL   // ;

	// Keywords
	// sql create table
	CREATE
	TABLE
	// sql insert
	INSERT
	INTO
	VALUES
	// sql select
	SELECT
	FROM

	// Column Types
	BOOL
	INT
	FLOAT
	STRING
	TIME
	BYTES
	UUID

	// Constraints
	NOTNULL
	PRIMARYKEY
	FOREIGNKEY
)

type Where

type Where struct {
	OperatorType OperatorType
	Value        interface{}
}

Where condisions to match

Jump to

Keyboard shortcuts

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