Skip to content
/ stable Public

STable is a simple string table engine with basic (C)RUD methods

License

Notifications You must be signed in to change notification settings

krpn/stable

Repository files navigation

stable

GoDoc Build Status Quality Gate Coverage Status Technical Debt License

  • STable is a simple string table engine with basic (C)RUD methods
  • All rows are stored as a map[string]string
  • Primary key and constraints are supported
  • Triggers are supported
  • It is safe calling STable methods from concurrently running goroutines

Installation

go get github.com/krpn/stable

Example Usage

package main

import (
	"fmt"
	"github.com/krpn/stable"
)

func main() {
	customers, err := stable.NewSTable(
		nil,                       // initial data
		"id",                      // primary key field
		[]string{"name", "phone"}, // requered fields
		[]string{"phone"},         // uniq fields
	)
	if err != nil {
		panic(err)
	}
	_, err = customers.Insert([]map[string]string{
		{"id": "1", "name": "Alex", "phone": "112233", "city": "New-York"},
		{"id": "2", "name": "John", "phone": "223344", "city": "New-York"},
		{"id": "3", "name": "Bill", "phone": "334455", "city": "London", "position": "JSON Senior Developer"},
	})
	if err != nil {
		panic(err)
	}
	row, err := customers.SelectAny(map[string]string{"city": "New-York"})
	if err != nil {
		panic(err)
	}
	fmt.Printf("%+v\n", row) // map[city:New-York id:1 name:Alex phone:112233]
	_, err = customers.Delete(map[string]string{"id": "2"})
	if err != nil {
		panic(err)
	}
	rows, err := customers.Select(nil)
	if err != nil {
		panic(err)
	}
	fmt.Printf("%+v\n", rows) // [map[city:New-York id:1 name:Alex phone:112233] map[city:London id:3 name:Bill phone:334455 position:JSON Senior Developer]]
}

About

STable is a simple string table engine with basic (C)RUD methods

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages