simdb

A simple IMDB (in-memory database) generator for go.
We generate type-safe and thread-safe IMDB.
We generate table with columns and also implement some methods like Get, Insert, Update, Delete, etc...
Usage
Basic Informations.
Table Info
| attribute |
explanation |
type |
|
| name |
name of table |
string |
required |
| is_private |
whether private or not |
bool |
|
| key_type |
type of key (this table's primary and an only unique key) |
string |
required |
| columns |
array of columns |
[]Columns |
|
Column Info
| attribute |
explanation |
type |
|
| name |
name of column |
string |
required |
| type |
type of column |
string |
requried |
| is_private |
whether private or not |
bool |
|
Setting args
| arg |
explanation |
positional or optional |
|
| file |
generated file name |
positional (1st arg) |
default is db.go |
| dir |
generated directory name |
optional |
default is current directory |
| package |
package name of generated |
optional |
requried (default is main) [can set in config file] |
| config |
config name withou extensions |
optional |
required (default is simdb) |
Examples
foo/gen.go
package gen
//go:generate go run github.com/maru44/simdb db.go --dir=bar --package=bench --config=conf
foo/conf.yaml
name: bench
is_private: true
key_type: int
columns:
- name: name
type: string
- name: email
type: string
- name: age
type: uint
is_private: true
- name: is_vald
type: bool
In this case, the generated file would be like following.
foo/bar/db.go
// Code generated by "github.com/maru44/simdb/gen"; DO NOT EDIT.
package bench
import (
"fmt"
"sync"
)
type (
bench struct {
Name string
Email string
age uint
IsValid bool
}
benchs struct {
data map[int]bench
sync.RWMutex
}
)
func NewBenchs() benchs {
return benchs{
data: map[int]bench{},
}
}
func (t *benchs) List() map[int]bench {
t.RLock()
defer t.RUnlock()
return t.data
}
...
A little bit better than sync.Map.
go test -bench . -benchmem ./bench
goos: darwin
goarch: arm64
pkg: github.com/maru44/simdb/_tests/bench
BenchmarkInsert-8 4487815 250.8 ns/op 246 B/op 0 allocs/op
BenchmarkInsert_SyncMap-8 2824500 432.6 ns/op 185 B/op 5 allocs/op
BenchmarkGet-8 12561126 116.3 ns/op 0 B/op 0 allocs/op
BenchmarkLoad-8 11806761 119.4 ns/op 0 B/op 0 allocs/op
BenchmarkLoad_SyncMap-8 7745020 177.0 ns/op 0 B/op 0 allocs/op
BenchmarkDelete-8 11140561 125.1 ns/op 0 B/op 0 allocs/op
BenchmarkDelete_SyncMap-8 7712466 175.9 ns/op 0 B/op 0 allocs/op