stowage

package module
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: LGPL-3.0 Imports: 9 Imported by: 0

README

STOWAGE

Generates a db access layer from a entity declaration source file.

Declaration

Entities

A declaration defines entities with their attributes and the relations between them.

entity document {
  title string
}

This example will implicitely add an ID attribute of type serial. It can also explicitely be defined like:

entity document {
  id serial
  title string
}

Or a custom id can be defined like:

entity document identified by domain, id {
  id serial
  domain string
  title string
}
Attribute types
serial

An auto incrementing integer type, usually used as a primary key. SOme database systems one support one per entity.

string

A text with at least 64k bytes. If it's used as part of an id it might need to be much shorter dependening on the database.

int

integer type, translates to go int which is signed 32 or 64 bit depending on architecture but is signed 32 bit in the rdbms.

float

double precision float type

bool

boolean type

enum
type enum (default = "", howto, help, topic = "topix")

Enum can be one of the provided values. The option = "..." part will overwrite the database value if it's different from the Identifier.

time

type with a date and time, will always be converted to and retrieved as UTC

reference
author -> user

Will add a relation from the entity to the user entity.

unique modifier
counter unique int

Will define a unique int field. In addition to the constraint it also generates an access method by that field.

Code generation

declaration := "entity foo { ..."

// generates golang access interfaces and datatypes in store pkg
gen, err := stowage.Generate(declaration, "store")
...

// generates postgres sql and access implementation in postgres pkg
err = gen.Postgres("postgres")
...

// generates cache which is valid for a transaction, implemented as a wrapper for a backend store
err = gen.TransactionCache("cache")
...


// generates plantuml db diagram in current folder
err = gen.PlantUML("./")
...

The generated codes provides an interface to access the database. All access goes trough transactions like:

err = store.Do("description", func(o store.Operation) error {
  // db access
  return nil
}

If inside the transaction function a panic is triggered or an error is returned the transaction is aborted.

The transaction instance provides methods to create/get/update entities.

id, err := o.CreateDocument(store.Document{Title: "first"})
...
doc, err := o.GetDocument(id)
...
doc.Title = "last"
err := o.UpdateDocument(doc)

To filter entities a select object is available:

docs, err := o.SelectDocument().TitleLike("%t").WithAuthor(johnID).Get()

The select object also provides methods to only retrieve ids, to count documents or to delete documents.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

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

func Generate

func Generate(source []byte, path string) (*Generator, error)

func (*Generator) MSSQL

func (g *Generator) MSSQL(path string) error

func (*Generator) MemDB

func (g *Generator) MemDB(path string) error

func (*Generator) MySQL

func (g *Generator) MySQL(path string) error

func (*Generator) PlantUML

func (g *Generator) PlantUML(path string, insertTop, insertBottom string) error

func (*Generator) Postgres

func (g *Generator) Postgres(path string) error

func (*Generator) Serializer

func (g *Generator) Serializer(path string) error

func (*Generator) Test

func (g *Generator) Test(path string) error

func (*Generator) TransactionCache

func (g *Generator) TransactionCache(path string) error

type NotFound

type NotFound struct {
	Entity    string
	Condition string
}

NotFound error is deprecated, it is generated into interface package

func (*NotFound) Error

func (n *NotFound) Error() string

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

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