entitydb

package module
v0.0.0-...-a133184 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: MIT Imports: 6 Imported by: 0

README

entitydb

Store unstructured data in postgres

Create the table in the postgres database
CREATE TABLE entity ( 
    id SERIAL PRIMARY KEY, 
    name TEXT,
    description TEXT,
    properties JSONB );
Create new entitydb instance
db := NewEntityDB(host, port, user, password, dbname)
Functions
Search
Insert
Lookup
Delete

Benchmark
goos: darwin
goarch: amd64
pkg: github.com/jkittell/entitydb
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
BenchmarkNewEntity-16          	  568731	      1913 ns/op
BenchmarkEntityDB_Search-16    	     262	   4996220 ns/op
BenchmarkEntityDB_Insert-16    	     358	   3374957 ns/op
BenchmarkEntityDB_Lookup-16    	     217	   5523728 ns/op
BenchmarkEntityDB_Delete-16    	     142	   8357930 ns/op

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetVal

func GetVal(data map[string]any, key string) (result any, found bool)

GetVal recursively searches through nested maps to find the key.

Types

type Entity

type Entity struct {
	Id          int         `db:"id"`
	Name        string      `db:"name"`
	Description string      `db:"description""`
	Properties  PropertyMap `db:"properties"`
}

Entity is a struct with same fields as database columns

type EntityDB

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

func NewEntityDB

func NewEntityDB(host string, port int, user, password, dbname string) (EntityDB, error)

func (*EntityDB) Delete

func (e *EntityDB) Delete(id int) (int, error)

func (*EntityDB) Insert

func (e *EntityDB) Insert(entity Entity) error

func (*EntityDB) Lookup

func (e *EntityDB) Lookup(id int) (Entity, error)

func (*EntityDB) Search

func (e *EntityDB) Search(key string, value interface{}) ([]Entity, error)

type PropertyMap

type PropertyMap map[string]interface{}

PropertyMap is a type for our properties field. Note that if you have different kinds of entities (orders, customers, books, ...), you can simply re-use this type if they have a similar field.

func (*PropertyMap) Scan

func (p *PropertyMap) Scan(src interface{}) error

Scan will take the JSONB data that comes from the database and transform it to the entity type.

func (PropertyMap) Value

func (p PropertyMap) Value() (driver.Value, error)

Value transforms the map to JSONB data or []byte

Jump to

Keyboard shortcuts

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