Skip to content

baobab.backend #

Backend

The purpose is to research ways in which actors can use generated code to use different ways of storing root objects.

Database Drivers

The Backend employs two database drivers:- Indexer, which drives an SQLite Database used to store base object gid's with relevant indexes

  • DBCollection which drives a collection of filesystem databases with encryption support

Generic Code

The solution provided by this module is to create a backend interface with generic CRUD + list + filter methods for root objects that different backends can implement.

This allows for a single generated actor code to use different backends, without having to generate separate code for each. Having less generated code is less prone to errors, and using the same backend methods for each actor makes it easier modify, fix and add features to the backends. Using the same data manipulation methods in generated code also makes it easier to generate code for the actor as the implementations don't differ for different root objects.

fn new #

fn new(config BackendConfig) !Backend

fn new_indexer #

fn new_indexer(db_path string, config IndexerConfig) !Indexer

fn reset #

fn reset(path string) !

deletes an indexer table belonging to a base object

struct Backend #

struct Backend {
pub mut:
	indexer Indexer
	dbs     dbfs.DBCollection
}

fn (Backend) delete #

fn (mut backend Backend) delete[T](id u32) !

fn (Backend) filter #

fn (mut backend Backend) filter[T, D](filter D, params FilterParams) ![]T

fn (Backend) generate_id #

fn (b Backend) generate_id() string

fn (Backend) get #

fn (mut backend Backend) get[T](id u32) !T

fn (Backend) list #

fn (mut backend Backend) list[T]() ![]T

fn (Backend) new #

fn (mut backend Backend) new[T](obj_ T) !u32

fn (Backend) reset #

fn (mut backend Backend) reset[T]() !

fn (Backend) reset_all #

fn (mut backend Backend) reset_all() !

fn (Backend) set #

fn (mut backend Backend) set[T](obj T) !

struct BackendConfig #

@[params]
struct BackendConfig {
pub:
	name   string
	secret string
	reset  bool
}

struct FilterParams #

@[params]
struct FilterParams {
	// indices     map[string]string // map of index values that are being filtered by, in order of priority.
	limit       int  // limit to the number of values to be returned, in order of priority
	fuzzy       bool // if fuzzy matching is enabled in matching indices
	matches_all bool // if results should match all indices or any
}

from and to for int f64 time etc.

struct Indexer #

struct Indexer {
	db sqlite.DB
}

fn (Indexer) delete_table #

fn (mut backend Indexer) delete_table[T]() !

deletes an indexer table belonging to a base object

fn (Indexer) new #

fn (mut backend Indexer) new[T](obj T) !

new creates a new root object entry in the root_objects table, and the table belonging to the type of root object with columns for index fields

fn (Indexer) set #

fn (mut backend Indexer) set[T](obj T) !

save the session to redis & mem

fn (Indexer) delete #

fn (mut backend Indexer) delete[T](id u32) !

save the session to redis & mem

fn (Indexer) get #

fn (mut backend Indexer) get[T](id string) !T

save the session to redis & mem

fn (Indexer) list #

fn (mut backend Indexer) list[T]() ![]T

save the session to redis & mem

fn (Indexer) filter #

fn (mut backend Indexer) filter[T, D](filter D, params FilterParams) ![]u32

filter lists root objects of type T that match provided index parameters and params.

struct IndexerConfig #

@[params]
struct IndexerConfig {
	reset bool
}

struct RootObject #

@[table: 'root_objects']
struct RootObject {
	id    int @[primary; sql: serial] // unique serial root object id
	table string // name of table root object is in
}