rmdb

package module
v0.0.0-...-98a5168 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

README

rmdb

关系型数据库可并发的对数据库进行增删改查操作,支持命令行交互,通过互斥锁实现可重复读隔离级别的事务,适合一致性要求强的业务场景,可以选择普通fileio和mmap两种读写模式,可自定义比较,聚合,对单列计算和多列计算的函数,通过buffer pool管理数据页,查询时通过将sql转化为执行计划进行查询

db, err := CreateDatabase("demo")
if err != nil {
    t.Fatal(err)
}
tab1, err := db.CreateTable("man")
if err != nil {
    t.Fatal(err)
}
err = tab1.SetColumn("name", STRING)
if err != nil {
    t.Fatal(err)
}
err = tab1.SetColumn("age", INT64)
if err != nil {
    t.Fatal(err)
}
tab2, err := db.CreateTable("thing")
if err != nil {
    t.Fatal(err)
}
err = tab2.SetColumn("id", INT64)
if err != nil {
    t.Fatal(err)
}
err = tab2.SetColumn("price", FLOAT64)
if err != nil {
    t.Fatal(err)
}
db.Update(`insert into man (name,age ) values ( "john",  8 );`)
db.Update(` insert into man (name,age)  values ("chris", 9 );`)
db.Update(`insert into thing  ( id ,price) values (0, 11.4) ; `)
db.Update(`  insert into thing ( id ,price) values ( 1, 5.14);`)
res1, _ := db.Query(` select * from  man`)
fmt.Println(res1.ToString())
res2, _ := db.Query(`select * from   thing`)
fmt.Println(res2.ToString())
err = db.Close()
if err != nil {
    t.Fatal(err)
}

Documentation

Index

Constants

View Source
const (
	KIB
	MIB
	GIB
)
View Source
const (
	BOOL = iota
	INT64
	FLOAT64
	STRING
	DATE
)
View Source
const (
	LogFatal   = LogType(0x1)
	LogError   = LogType(0x2)
	LogWarning = LogType(0x4)
	LogInfo    = LogType(0x8)
	LogDebug   = LogType(0x10)
)
View Source
const (
	LogLevelNone  = LogLevel(0x0)
	LogLevelFatal = LogLevelNone | LogLevel(LogFatal)
	LogLevelError = LogLevelFatal | LogLevel(LogError)
	LogLevelWarn  = LogLevelError | LogLevel(LogWarning)
	LogLevelInfo  = LogLevelWarn | LogLevel(LogInfo)
	LogLevelDebug = LogLevelInfo | LogLevel(LogDebug)
	LogLevelAll   = LogLevelDebug
)
View Source
const (
	Standard = iota
	MMapMode
)
View Source
const (
	TableRead = iota
	Projection
	Selection
	Aggregation
	FuncCol
	Execute
	Rename
	Having
	Distinct
	Sorting
	Limit
)

Variables

View Source
var (
	GlobalOption = &Option{
		Root:       "E:\\golangProject\\demo2\\dbtest",
		IOMode:     Standard,
		CondiFuncs: make(map[string]func([]any) bool, 64),
		ColFuncs:   make(map[string]func(any) any, 64),
		AggFuncs:   make(map[string]func([]any) any, 64),
		ExecFuncs:  make(map[string]func([]any) any, 64),
		MmapSize:   16 * MIB,
		MaxPage:    4,
		MaxLine:    4,
	}
)

Functions

func CheckParentheses

func CheckParentheses(sql string) bool

func ConvertQuery

func ConvertQuery(sql string) []string

func DecodeData

func DecodeData(data []byte, typeOf int) (any, error)

func DropDatabase

func DropDatabase(name string) error

func EncodeData

func EncodeData(data any) ([]byte, error)

func GetTypeOf

func GetTypeOf(value any) int

func GlobalLogger

func GlobalLogger() *log.Logger

func LogTypeToString

func LogTypeToString(t LogType) (string, string)

func NewColName

func NewColName(funcName string, colNames ...string) string

func RunClient

func RunClient()

func RunServer

func RunServer()

func ShowDatabase

func ShowDatabase() string

func TrimSpace

func TrimSpace(str string) string

Types

type AggregationPlan

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

type Client

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

type ColVal

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

type Column

type Column struct {
	Name   string
	TypeOf int
	DefVal []byte
}

type Database

type Database struct {
	CondiFuncs map[string]func([]any) bool
	ColFuncs   map[string]func(any) any
	AggFuncs   map[string]func([]any) any
	ExecFuncs  map[string]func([]any) any
	// contains filtered or unexported fields
}

func CreateDatabase

func CreateDatabase(name string) (*Database, error)

func UseDatabase

func UseDatabase(name string) (*Database, error)

func (*Database) Begin

func (d *Database) Begin() *Transaction

func (*Database) Close

func (d *Database) Close() error

func (*Database) CreateTable

func (d *Database) CreateTable(name string) (*Table, error)

func (*Database) DropTable

func (d *Database) DropTable(name string) error

func (*Database) Query

func (d *Database) Query(sql string) (*ResultSet, error)

func (*Database) ShowTables

func (d *Database) ShowTables() string

func (*Database) Update

func (d *Database) Update(sql string) error

type DistinctPlan

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

type ExecutePlan

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

type FileIO

type FileIO interface {
	Write(b []byte) (n int, err error)
	ReadAt(b []byte, off int64) (n int, err error)
	Name() string
	Sync() error
	Close() error
}

func NewMMap

func NewMMap(path string, size int64) (FileIO, error)

func OpenFile

func OpenFile(path string) (FileIO, error)

type FuncColPlan

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

type HavingPlan

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

type LimitPlan

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

type Line

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

func CopyLine

func CopyLine(line Line) Line

type LogLevel

type LogLevel int

func GetLogLevel

func GetLogLevel() LogLevel

func StringToLogLevel

func StringToLogLevel(level string) LogLevel

type LogType

type LogType int

type Logger

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

func NewLogger

func NewLogger(w io.Writer, prefix string) *Logger

func (*Logger) Debug

func (l *Logger) Debug(v ...interface{})

func (*Logger) Debugf

func (l *Logger) Debugf(format string, v ...interface{})

func (*Logger) Error

func (l *Logger) Error(v ...interface{})

func (*Logger) Errorf

func (l *Logger) Errorf(format string, v ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(v ...interface{})

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, v ...interface{})

func (*Logger) Flags

func (l *Logger) Flags() int

func (*Logger) Info

func (l *Logger) Info(v ...interface{})

func (*Logger) Infof

func (l *Logger) Infof(format string, v ...interface{})

func (*Logger) Panic

func (l *Logger) Panic(v ...interface{})

func (*Logger) Panicf

func (l *Logger) Panicf(format string, v ...interface{})

func (*Logger) SetFlags

func (l *Logger) SetFlags(flags int)

func (*Logger) SetHighlighting

func (l *Logger) SetHighlighting(highlighting bool)

func (*Logger) SetLevel

func (l *Logger) SetLevel(level LogLevel)

func (*Logger) SetLevelByString

func (l *Logger) SetLevelByString(level string)

func (*Logger) Warn

func (l *Logger) Warn(v ...interface{})

func (*Logger) Warnf

func (l *Logger) Warnf(format string, v ...interface{})

type LruCache

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

func (*LruCache) AddPage

func (l *LruCache) AddPage(page *Page) error

func (*LruCache) CopyPage

func (l *LruCache) CopyPage(pageId uint64) (*Memtable, error)

func (*LruCache) GetPage

func (l *LruCache) GetPage(id uint64) (*Page, error)

func (*LruCache) NewPage

func (l *LruCache) NewPage() (*Page, error)

func (*LruCache) RemoveOld

func (l *LruCache) RemoveOld() error

type MMap

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

func (*MMap) Close

func (m *MMap) Close() error

func (*MMap) Delete

func (m *MMap) Delete() error

func (*MMap) Name

func (m *MMap) Name() string

func (*MMap) ReadAt

func (m *MMap) ReadAt(b []byte, offset int64) (int, error)

func (*MMap) Sync

func (m *MMap) Sync() error

func (*MMap) Write

func (m *MMap) Write(b []byte) (int, error)

type Memtable

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

type Option

type Option struct {
	Root             string
	IOMode           int
	CondiFuncs       map[string]func([]any) bool
	ColFuncs         map[string]func(any) any
	AggFuncs         map[string]func([]any) any
	ExecFuncs        map[string]func([]any) any
	MmapSize         int64
	MaxPage, MaxLine uint64
	// contains filtered or unexported fields
}

func (*Option) SetAggFunc

func (o *Option) SetAggFunc(name string, function func([]any) any)

func (*Option) SetColFunc

func (o *Option) SetColFunc(name string, function func(any) any)

func (*Option) SetCondiFunc

func (o *Option) SetCondiFunc(name string, function func([]any) bool)

func (*Option) SetExecFunc

func (o *Option) SetExecFunc(name string, function func([]any) any)

type Page

type Page struct {
	Id uint64

	Offset, Length uint64
	// contains filtered or unexported fields
}

func (*Page) DecodeLine

func (p *Page) DecodeLine(data []byte) Line

func (*Page) DecodePage

func (p *Page) DecodePage(data []byte)

func (*Page) EncodeLine

func (p *Page) EncodeLine(line Line) []byte

func (*Page) EncodePage

func (p *Page) EncodePage() []byte

func (*Page) InsertLine

func (p *Page) InsertLine(line Line) bool

type Plan

type Plan interface {
	// contains filtered or unexported methods
}

type ProjectionPlan

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

type RenamePlan

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

type ResultSet

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

func (*ResultSet) ToString

func (r *ResultSet) ToString() string

type SelectionPlan

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

type Server

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

func NewServer

func NewServer(host string, port int) (*Server, error)

func (*Server) Listen

func (s *Server) Listen() error

func (*Server) Stop

func (s *Server) Stop()

type SortingPlan

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

type SubTx

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

type Table

type Table struct {
	Name string

	Columns []Column

	Catalog map[uint64]Page
	// contains filtered or unexported fields
}

func (*Table) Close

func (t *Table) Close() error

func (*Table) Merge

func (t *Table) Merge(dbPath string) error

func (*Table) SetColumn

func (t *Table) SetColumn(name string, typeOf int) error

type TableReadPlan

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

type Transaction

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

func (*Transaction) Commit

func (t *Transaction) Commit() error

func (*Transaction) CompileQuery

func (t *Transaction) CompileQuery(slice []string, wg *sync.WaitGroup) (map[int]Plan, []string, string, error)

func (*Transaction) CompileUpdate

func (t *Transaction) CompileUpdate(sql string) error

func (*Transaction) Query

func (t *Transaction) Query(sql string) (*ResultSet, error)

func (*Transaction) Rollback

func (t *Transaction) Rollback() error

func (*Transaction) Update

func (t *Transaction) Update(sql string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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