g0database

package module
v0.0.0-...-3ae6550 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2024 License: MIT Imports: 5 Imported by: 0

README

g0database

Github Actions codecov

A SQL database, written from scratch in Go

Inspired by

Lexer

  • Split raw sql command to token

raw sql: select id, name, age from user where status = 'ACTIVE' and id > 10

=> tokens: ["select", "id", ",", "name", ",", "age", "from", "user", "where", "status", "=", "'", "ACTIVE", "'", "and", "id", ">", "10"]

Parser

  • Make Abstract syntax tree (AST) from list tokens
root
 |- select
 |---- fields (id, name, age)
 |- from
 |---- tables (user)
 |- where
 |---- conditions
           |---- status
           |---- =
           |---- ACTIVE
       |- AND
           |---- id
           |---- >
           |---- 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Name     string
	Datatype DataType
	DataSize int
	Value    interface{}
}

type Command

type Command interface {
	GetType() CommandType
}

type CommandCreate

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

func (*CommandCreate) GetType

func (c *CommandCreate) GetType() CommandType

type CommandResult

type CommandResult struct {
	Output      string
	IsTerminate bool
}

type CommandSelect

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

func (*CommandSelect) GetType

func (c *CommandSelect) GetType() CommandType

type CommandType

type CommandType string
const (
	CommandTypeSelect CommandType = "select"
	CommandTypeUpdate CommandType = "update"
	CommandTypeDelete CommandType = "delete"
	CommandTypeInsert CommandType = "insert"
	CommandTypeCreate CommandType = "create"
)

type DataSource

type DataSource interface {
	Schema() (*Schema, error)
	FromFile(filePath string) error
}

func NewDataSource

func NewDataSource(sourceType DataSourceType) DataSource

type DataSourceType

type DataSourceType string
const (
	DataSourceTypeCsv DataSourceType = "csv"
)

type DataType

type DataType string
const (
	DataTypeInt      DataType = "int"
	DataTypeBigInt   DataType = "bigint"
	DataTypeVarchar  DataType = "varchar"
	DataTypeDateTime DataType = "datetime"
)

type Executor

type Executor interface {
	Execute(cmd Command) CommandResult
}

func NewExecutor

func NewExecutor() Executor

type Lexer

type Lexer interface {
	Analyze(string) ([]Token, error)
}

func NewNaiveLexer

func NewNaiveLexer() Lexer

type Parser

type Parser interface {
	Parse(tokens []Token) (Command, error)
}

func NewParser

func NewParser() Parser

type Schema

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

type Table

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

type Token

type Token string

type TokenType

type TokenType int
const (
	TokenTypeKeyword    TokenType = iota // SELECT, UPDATE
	TokenTypeIdentifier                  // var name
	TokenTypeOperator                    // + - * /
	TokenTypeSeparator                   // , ;
)

Jump to

Keyboard shortcuts

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