nervatura

package
v0.0.0-...-2645eb2 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const IList = "[]interface{}"

IList is a []interface{} string const

View Source
const TimeLayout = "2006-01-02 15:04:05"

TimeLayout DateTime format

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	NStore *NervaStore
}

API - Application Programming Interface

See more docs and examples: https://nervatura.github.io/nervatura/api

func (*API) DatabaseCreate

func (api *API) DatabaseCreate(options IM) ([]SM, error)

DatabaseCreate - create a Nervatura Database

All data will be destroyed!

Example:

options := map[string]interface{}{
  "database": alias,
  "demo": true,
  "report_dir": ""}
_, err := getAPI().DatabaseCreate(options)

func (*API) Delete

func (api *API) Delete(options IM) error

Delete - delete a record

Examples:

Delete data by ID:

options = map[string]interface{}{"nervatype": "address", "id": 2}
err = api.Delete(options)

Delete data by Key:

options = map[string]interface{}{"nervatype": "address", "key": "customer/DMCUST/00001~1"}
err = api.Delete(options)

func (*API) Function

func (api *API) Function(options IM) (results interface{}, err error)

Function - call a server-side function

Examples:

  The next value from the numberdef table (customer, product, invoice etc.):

  options := map[string]interface{}{
    "key": "nextNumber",
    "values": map[string]interface{}{
      "numberkey": "custnumber",
      "step":      false,
    },
  }
  _, err = api.Function(options)

  Product price (current date, all customer, all qty):

  options = map[string]interface{}{
    "key": "getPriceValue",
    "values": map[string]interface{}{
      "curr":        "EUR",
      "product_id":  2,
      "customer_id": 2,
    },
  }
  _, err = api.Function(options)

  Email sending with attached report:

	options := map[string]interface{}{
		"key": "sendEmail",
		"values": map[string]interface{}{
			"provider": "smtp",
			"email": map[string]interface{}{
				"from": "info@nervatura.com", "name": "Nervatura",
				"recipients": []interface{}{
					map[string]interface{}{"email": "sample@company.com"}},
				"subject": "Demo Invoice",
				"text":    "Email sending with attached invoice",
				"attachments": []interface{}{
					map[string]interface{}{
						"reportkey": "ntr_invoice_en",
						"nervatype": "trans",
						"refnumber": "DMINV/00001"}},
			},
		},
	}

func (*API) Get

func (api *API) Get(options IM) (results []IM, err error)

Get - returns one or more records

Examples:

Find data by Filter:

options = map[string]interface{}{"nervatype": "customer", "metadata": true,
  "filter": "custname;==;First Customer Co.|custnumber;in;DMCUST/00001,DMCUST/00002"}
_, err = api.Get(options)

Find data by IDs:

options = map[string]interface{}{"nervatype": "customer", "metadata": true, "ids": "2,4"}
_, err = api.Get(options)

func (*API) Report

func (api *API) Report(options IM) (results IM, err error)

Report - server-side PDF and CSV report generation

Examples:

Customer PDF invoice:

options := map[string]interface{}{
  "reportkey":   "ntr_invoice_en",
  "orientation": "portrait",
  "size":        "a4",
  "nervatype":   "trans",
  "refnumber":   "DMINV/00001",
}
_, err = api.Report(options)

Customer invoice XML data:

options = map[string]interface{}{
  "reportkey": "ntr_invoice_en",
  "output":    "xml",
  "nervatype": "trans",
  "refnumber": "DMINV/00001",
}
_, err = api.Report(options)

CSV report:

options = map[string]interface{}{
  "reportkey": "csv_vat_en",
  "filters": map[string]interface{}{
    "date_from": "2014-01-01",
    "date_to":   "2019-01-01",
    "curr":      "EUR",
  },
}
_, err = api.Report(options)

func (*API) ReportDelete

func (api *API) ReportDelete(options IM) (err error)

ReportDelete - delete a report from the database

Example:

options := nt.IM{
  "reportkey": "ntr_cash_in_en",
}
err = api.ReportDelete(options)

func (*API) ReportInstall

func (api *API) ReportInstall(options IM) (result int64, err error)

ReportInstall - install a report to the database

Example:

options := nt.IM{
  "report_dir": "",
  "reportkey":  "ntr_cash_in_en",
}
_, err = api.ReportInstall(options)

func (*API) ReportList

func (api *API) ReportList(options IM) (results []IM, err error)

ReportList - returns all installable files from the NT_REPORT_DIR (environment variable) or report_dir (options) directory

Example:

options := map[string]interface{}{
  "report_dir": "",
}
_, err = api.ReportList(options)

func (*API) TokenLogin

func (api *API) TokenLogin(options IM) error

TokenLogin - database JWT token auth.

Example:

options := map[string]interface{}{"token": "JWT_token"}
err := getAPI().TokenLogin(options)

func (*API) TokenRefresh

func (api *API) TokenRefresh() (string, error)

TokenRefresh - create/refresh a JWT token

func (*API) Update

func (api *API) Update(nervatype string, data []IM) (results []int64, err error)

Update - Add or update one or more items

If the ID (or Key) value is missing, it creates a new item. Returns the all new/updated IDs values.

Examples:

addressData := []map[string]interface{}{
  map[string]interface{}{
    "nervatype":         10,
    "ref_id":            2,
    "zipcode":           "12345",
    "city":              "BigCity",
    "notes":             "Create a new item by IDs",
    "address_metadata1": "value1",
    "address_metadata2": "value2~note2"},
  map[string]interface{}{
    "id":                6,
    "zipcode":           "54321",
    "city":              "BigCity",
    "notes":             "Update an item by IDs",
    "address_metadata1": "value1",
    "address_metadata2": "value2~note2"},
  map[string]interface{}{
    "keys": map[string]interface{}{
      "nervatype": "customer",
      "ref_id":    "customer/DMCUST/00001"},
    "zipcode":           "12345",
    "city":              "BigCity",
    "notes":             "Create a new item by Keys",
    "address_metadata1": "value1",
    "address_metadata2": "value2~note2"},
  map[string]interface{}{
    "keys": map[string]interface{}{
      "id": "customer/DMCUST/00001~1"},
    "zipcode":           "54321",
    "city":              "BigCity",
    "notes":             "Update an item by Keys",
    "address_metadata1": "value1",
    "address_metadata2": "value2~note2"}}

_, err = api.Update("address", addressData)

func (*API) UserLogin

func (api *API) UserLogin(options IM) (string, string, error)

UserLogin - database user login

Returns a access token and the type of database.

options := map[string]interface{}{
  "database": "alias_name",
  "username": "username",
  "password": "password"}
token, engine, err := getAPI().UserLogin(options)

func (*API) UserPassword

func (api *API) UserPassword(options IM) error

UserPassword - set/change a user password

Example:

options = map[string]interface{}{
  "username": "demo",
  "password": "321",
  "confirm": "321"}
err = api.UserPassword(options)

func (*API) View

func (api *API) View(options []IM) (results IM, err error)

View - run raw SQL queries in safe mode

Only "select" queries and functions can be executed. Changes to the data are not saved in the database.

Examples:

options := []map[string]interface{}{
  map[string]interface{}{
    "key":    "customers",
    "text":   "select c.id, ct.groupvalue as custtype, c.custnumber, c.custname from customer c inner join groups ct on c.custtype = ct.id where c.deleted = 0 and c.custnumber <> 'HOME'",
  },
  map[string]interface{}{
    "key":    "invoices",
    "text":   "select t.id, t.transnumber, tt.groupvalue as transtype, td.groupvalue as direction, t.transdate, c.custname, t.curr, items.amount from trans t inner join groups tt on t.transtype = tt.id inner join groups td on t.direction = td.id inner join customer c on t.customer_id = c.id inner join ( select trans_id, sum(amount) amount from item where deleted = 0 group by trans_id) items on t.id = items.trans_id where t.deleted = 0 and tt.groupvalue = 'invoice'",
  },
}
_, err = api.View(options)

type DataDriver

type DataDriver interface {
	Properties() struct {
		SQL, Transaction bool
	} //DataDriver features
	Connection() struct {
		Alias     string
		Connected bool
		Engine    string
	} //Returns the database connection
	CreateConnection(string, string) error                                                  //Create a new database connection
	CreateDatabase(logData []SM) ([]SM, error)                                              //Create a Nervatura Database
	CheckHashtable(hashtable string) error                                                  //Check/create a password ref. table
	UpdateHashtable(hashtable, refname, value string) error                                 //Set a password
	Query(queries []Query, transaction interface{}) ([]IM, error)                           //Query is a basic nosql friendly queries the database
	QuerySQL(sqlString string, params []interface{}, transaction interface{}) ([]IM, error) //Executes a SQL query
	QueryKey(options IM, transaction interface{}) ([]IM, error)                             //Complex data queries
	Update(options Update) (int64, error)                                                   //Update is a basic nosql friendly update/insert/delete and returns the update/insert id
	BeginTransaction() (interface{}, error)                                                 //Begins a transaction and returns an it
	CommitTransaction(trans interface{}) error                                              //Commit a transaction
	RollbackTransaction(trans interface{}) error                                            //Rollback a transaction
	CloseConnection() error
}

DataDriver a general database interface

type Filter

type Filter struct {
	Or    bool   // and (False) or (True)
	Field string //Fieldname and alias
	Comp  string //==,!=,<,<=,>,>=,in,is
	Value interface{}
}

Filter query filter type

type IL

type IL = []interface{}

IL is a []interface{} type short alias

type IM

type IM = map[string]interface{}

IM is a map[string]interface{} type short alias

func DataModel

func DataModel() IM

DataModel - database table models

type MF

type MF = ModelField

MF is a ModelField type short alias

type MI

type MI = ModelIndex

MI is a ModelIndex type short alias

type ModelField

type ModelField struct {
	Type       string //Valid values:"id",integer","float","string","text","date","datetime"
	Unique     bool
	NotNull    bool
	Length     int
	Default    interface{} //Default value
	Requires   IM          //Field validation rules
	References []string
	Refname    string
}

ModelField - Model (table/document) field description

type ModelIndex

type ModelIndex struct {
	Model  string
	Fields []string
	Unique bool
}

ModelIndex - Model index description

type NervaStore

type NervaStore struct {
	User     *User
	Customer IM
	// contains filtered or unexported fields
}

NervaStore is the core structure of the Nervatura

func New

func New(driver DataDriver, config IM) (nstore *NervaStore)

New returns a pointer to a new NervaStore instance.

func (*NervaStore) Connection

func (nstore *NervaStore) Connection() (conn struct {
	Alias     string
	Connected bool
	Engine    string
})

Connection - get nstore conn. properties

func (*NervaStore) DeleteData

func (nstore *NervaStore) DeleteData(options IM) (err error)

DeleteData - delete a record data

func (*NervaStore) GetDataAudit

func (nstore *NervaStore) GetDataAudit() (string, error)

GetDataAudit - Nervatura data access rights: own,usergroup,all (transfilter) see more: employee.usergroup+link+transfilter

func (*NervaStore) GetGroups

func (nstore *NervaStore) GetGroups(options IM) (IM, error)

GetGroups - returns Nervatura groups map

func (*NervaStore) GetInfofromRefnumber

func (nstore *NervaStore) GetInfofromRefnumber(options IM) (IM, error)

GetInfofromRefnumber - returns id and other info from public key

func (*NervaStore) GetObjectAudit

func (nstore *NervaStore) GetObjectAudit(options IM) ([]string, error)

GetObjectAudit - Nervatura objects access rights: disabled,readonly,update,all (inputfilter) see more: audit

func (*NervaStore) GetRefnumber

func (nstore *NervaStore) GetRefnumber(options IM) (IM, error)

GetRefnumber - returns public key from id

func (*NervaStore) GetService

func (nstore *NervaStore) GetService(key string, options IM) (interface{}, error)

GetService - call Nervatura server side functions and services

func (*NervaStore) UpdateData

func (nstore *NervaStore) UpdateData(options IM) (id int64, err error)

UpdateData - update a record data

type Query

type Query struct {
	Fields  []string //Returns fields
	From    string   //Table or doc. name and alias
	Filters []Filter
	Filter  string //filter string (eg. "id=1 and field='value'")
	OrderBy []string
}

Query data desc. type

type SL

type SL = []string

SL is a []string type short alias

type SM

type SM = map[string]string

SM is a map[string]string type short alias

type SessionService

type SessionService struct {
	Config          IM
	Conn            DataDriver
	Method          string
	MemSession      IM
	CreateDir       func(name string, perm fs.FileMode) error
	CreateFile      func(name string) (*os.File, error)
	ReadFile        func(name string) ([]byte, error)
	FileStat        func(name string) (fs.FileInfo, error)
	ConvertToByte   func(data interface{}) ([]byte, error)
	ConvertFromByte func(data []byte, result interface{}) error
}

SessionService implements the session service

func (*SessionService) LoadSession

func (ses *SessionService) LoadSession(sessionKey string, data any) (result any, err error)

func (*SessionService) SaveSession

func (ses *SessionService) SaveSession(sessionKey string, data any)

type Update

type Update struct {
	Values IM
	Model  string
	IDKey  int64       //Update, delete or insert exec
	Trans  interface{} //Transaction
}

Update data desc. type

type User

type User struct {
	Id         int64  `json:"id"`
	Username   string `json:"username"`
	Empnumber  string `json:"empnumber"`
	Usergroup  int64  `json:"usergroup"`
	Scope      string `json:"scope"`
	Department string `json:"department,omitempty"`
}

User - Nervatura user properties

Jump to

Keyboard shortcuts

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