Type Definitions
ConfigOptions
Config parameters defined in a module as a list of objects.
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
name |
string | parameter name, can be a string regexp to match dynamic parameters, matched pieces then can be used by the make property to build the final variable name. |
|
descr |
string | parameter description, it is show when run bksh -help command |
|
type |
string |
<optional> |
a valid config type:
|
obj |
string |
<optional> |
object name in the module where to store the value, otherwise the value is defined in the module, the obj name is stripped automatically from the variable name. The object name can contain dots to point to deep objects inside the module. |
make |
string |
<optional> |
make the variable name from the matched pieces, the final variable is constructed by replacing every $1, $2, ... with corresponding matched piece from the name regexp. |
array |
boolean |
<optional> |
if true prepend a value to the list, to remove an item prepend it with !! |
push |
boolean |
<optional> |
for array: mode append a value |
pass |
int |
<optional> |
process only args that match the pass value |
env |
string |
<optional> |
env variable name to apply before parsing config files |
merge |
boolean |
<optional> |
if true merge properties with existing object, 'obj' must be provided |
dot |
boolean |
<optional> |
if true and the name contains dots it is treated as deep object |
maptype |
string |
<optional> |
default is auto to parse map values or can be any value type, for type map |
make |
string |
<optional> |
works with regexp names like name-([a-z]+)-(.+) to build the final parameter name, can use $1, $2, $3...placeholders |
novalue |
string | Array.<string> |
<optional> |
skip if value is equal or included in the list, also works for merges |
sort |
boolean |
<optional> |
sort array params |
unique |
boolean |
<optional> |
only keep unique items in lists |
camel |
string |
<optional> |
characters to use when camelizing the name, default is "-" |
nocamel |
boolean |
<optional> |
do not camelize the name |
noempty |
boolean |
<optional> |
do not save empty values |
autotype |
boolean |
<optional> |
detect type by using module:lib.autoType |
novalue |
string | Array.<string> |
<optional> |
do not save if matches given string or contained in the list |
example |
string |
<optional> |
text with examples |
callback |
function |
<optional> |
function to call for the callback types for manully parsing and setting the value, (value, obj) the obj being current parameter |
onupdate |
function | string |
<optional> |
function to call at the end for additional processing as (value, obj) |
separator |
string |
<optional> |
separator to use for list and map items, for lists default is ,|, for maps it is :; |
delimiter |
string |
<optional> |
separator to split key:value pairs, default is , |
empty |
boolean |
<optional> |
allows empty values for maps and regexps |
ephemeral |
boolean |
<optional> |
parsed but not saved, usually it is handled by onupdate callback |
strip |
string |
<optional> |
text to stripo from the final variable name |
once |
boolean |
<optional> |
only set this parameter once |
Type:
- object
DbConfigOptions
Common options for the pools that customize behaviour
Properties:
| Name | Type | Description |
|---|---|---|
upgrade |
boolean | perform alter table instead of create |
typesMap |
boolean | type mapping, convert lowercase type into other type supported by any specific database |
noDefaults |
boolean | ignore default value if not supported (Cassandra) |
noNulls |
boolean | NOT NULL restriction is not supported (Cassandra) |
noMultiSQL |
boolean | return as a list, the driver does not support multiple SQL commands |
noLengths |
boolean | ignore column length for columns (Cassandra) |
noIfExists |
boolean | do not support IF EXISTS on table or indexes |
noCompositeIndex |
boolean | does not support composite indexes (Cassandra) |
noAuto |
boolean | no support for auto increment columns |
skipNull |
boolean | object with operations which dont support null(empty) values |
DbRequestColumn
A column prepared to be used in conditions, see module:db.prepareColumn
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
name |
string | actual column name |
|
type |
string | type from DbTableColumn |
|
op |
string | operator to use in comparison or update, lowercase and all underscores are converted into spaces |
|
value |
any | value passed for compare or update |
|
join |
string | join operator, AND is default |
|
alias |
string | original name in case name contained _$ placeholder |
|
col |
DbTableColumn |
<optional> |
existing column definition or undefined |
DbRequestOptions
Properties:
| Name | Type | Description |
|---|---|---|
pool |
string | name of the database pool where to execute this query. The difference with the high level functions that take a table name as their firt argument, this function must use pool explicitely if it is different from the default. Other functions can resolve the pool by table name if some tables are assigned to any specific pool by configuration parameters `db-pool-tables__. |
filterrows |
function | function to filter rows not to be included in the result, returns a new result set, args are: function(req, rows) |
processrows |
function | function to process rows in the result, returns a new result, args are: function(req, rows), this result will be put in cache if requested so this may be used for preparing cached results, it must return an array |
processasync |
function | function to process result rows via async callback, return a new result in the callback, the function is: function(req, rows, callback), the callback is function(err, rows) |
logger_db |
string | log results at the end with this level or debug by default |
logger_error |
string | log errors with this level instead of error |
ignore_error |
boolean | Array.<string> | clear errors occurred as it never happen, do not report in the log, if an array then only matched codes will be cleared |
noprocessrows |
boolean | if true then skip post processing result rows, return the data as is, this will result in returning combined columns as it is |
noconvertrows |
boolean | if true skip converting the data from the database format into Javascript data types, it uses column definitions |
nopreparequery |
boolean | if true skip query preparation and columns processing, the req.query is passed as is, useful for syncing between pools for the table to convert values returned from the db into the the format defined by the column |
total |
boolean | if true then it is supposed to return only one record with property count, skip all post processing and convertion |
info_query |
boolean | to return the record just processed in the info object as query property, it will include all generated and updated columns |
result_query |
boolean | to return the query record as result including all post processing and new generated columns, this is not what returning property does, it only returns the query record with new columns from memory |
cached |
boolean | if true then run getCached version directly |
nocache |
boolean | disable caching even if configured for the table |
ops |
object | operators to use for for properties, an object with column name and operator. Comparison operators used in select/get:
Update operators used in incr/update/del:
As an alternative, operators also can be used inside column names, the format is name_$op: |
opsMap |
object | operator mapping between supplied operators and actual operators supported by the db |
typesOps |
object | an object that defines ops by column type, for example typesOps: { list: "add" } will |
typesMap |
object | type mapping between supplied and actual column types, an object make sure all lists will have options.ops set to add if not specified explicitly |
select |
string | Array.<string> | a list of columns or expressions to return or all columns if not specified, only existing columns will be returned |
start |
string | object | start records with this primary key, this is the next_token passed by the previous query from module.db.select |
count |
int | how many records to retrieve in a single batch |
first |
boolean | a convenient option to return the first record from the result or null (similar to db.get method) |
last |
boolean | similar to first but return the last record |
join |
string | how to join condition expressions, default is AND |
joinOps |
object | operators to use to combine several expressions in case when an array of values is given, supports and|or|AND|OR__ |
sort |
string | sort by this column. if not provided then no sorting must be done at all, records will be returned in the order they are kept in the DB.
|
desc |
boolean | if sorting, do in descending order |
page |
int | starting page number for pagination, uses count to find actual record to start, for SQL databases mostly |
cacheKey |
string | exlicit key for caching, return from the cache or from the DB and then cache it with this key, works the same as get |
cacheKeyName |
string | a name of one of the cache keys to use, it must be defined by a db-cache-keys-table-name parameter |
no_columns |
boolean | do not check for actual columns defined in the pool tables and add all properties from the obj, only will work for NoSQL dbs, by default all properties in the obj not described in the table definition for the given table will be ignored. |
skip_columns |
Array.<string> | ignore properties by name listed in the this array, the most use case is to skip autogeneratd columns like "now" |
query |
object | an object with the condition for the update/incr ops, it is used instead or in addition to the primary keys in the query, a property named $or/$and will be treated as a sub-expression if it is an object. For multiple OR/AND use $$or, $$$or,... |
upsert |
boolean | create a new record if it does not exist |
useCapacity |
string | triggers to use specific capacity, default is read |
factorCapacity |
number | a factor to apply for the read or write capacity limit and trigger the capacity check, default is 0.9 |
tableCapacity |
string | use a different table for capacity throttling instead of the table, useful for cases when the row callback performs writes into that other table and capacity is different |
capacity |
object | a full capacity object to pass to select calls, used by module:db.checkCapacity |
batch |
boolean | if true rowCallback will be called with all rows from the batch, used in module:db.scan not every row individually, batch size is defined by the count property, used in module:db.scan |
sync |
boolean | as batch mode but the rowCallback is called synchronously as rowCallback(row, info), used in module:db.scan |
concurrency |
number | how many rows or operations to process at the same time, used in module:db.scan, module:db.batch |
limit |
number | total number of records to scan, used in module:db.scan |
noscan |
boolean | if true no scan will be performed if no primary keys are specified to prevent scanning large tables, used in module:db.scan |
fullscan |
boolean | if true force to perform a full scan, this is slightly different for each database, used in module:db.scan:
|
syncMode |
boolean | skip column preprocessing and dynamic values for pool sync and backup restore, used in module:db.copy |
Type:
- object
DbResultCallback(err, rows, info)
This callback is called by all DB methods
Parameters:
| Name | Type | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
err |
Error | and error object or null i fno errors |
||||||||||||||||||||
rows |
Array.<object> | a list of result rows, in case of error it is an empty list |
||||||||||||||||||||
info |
object | an object with information about the last query: Properties
|
DbTable
Database table object, each property represents a column
Properties:
| Name | Type | Description |
|---|---|---|
name1 |
DbTableColumn | column1 |
name2 |
DbTableColumn | column2 |
... |
DbTableColumn | more columns |
Type:
- object
DbTableColumn
Database column definition, all properties are optional
Properties:
| Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
type |
string | column type, supported types:
|
|||||||||||||||||||||||||||||||||||||||||||
primary |
int | column is part of the primary key, for composite keys the number defines the place starting with 1 |
|||||||||||||||||||||||||||||||||||||||||||
unique |
int | column is part of an unique key, the number defines the order if it is composite key |
|||||||||||||||||||||||||||||||||||||||||||
index |
int | column is part of an index, the value is a number for the column position in the index |
|||||||||||||||||||||||||||||||||||||||||||
uniqueN |
int | additonal unique indexes where N is 1..25 |
|||||||||||||||||||||||||||||||||||||||||||
indexN |
int | additonal indexes where N is 1..25 |
|||||||||||||||||||||||||||||||||||||||||||
value |
any | default value to save if not provided |
|||||||||||||||||||||||||||||||||||||||||||
dflt |
any | default value to return if not present in the db record |
|||||||||||||||||||||||||||||||||||||||||||
length |
int | column length (SQL) |
|||||||||||||||||||||||||||||||||||||||||||
not_null |
boolean | true if should be NOT NULL (SQL) |
|||||||||||||||||||||||||||||||||||||||||||
auto |
boolean | true for AUTO_INCREMENT column (SQL) |
|||||||||||||||||||||||||||||||||||||||||||
readonly |
boolean | only add/put operations will use the value, incr/update will not affect the value |
|||||||||||||||||||||||||||||||||||||||||||
writeonly |
boolean | only incr/update can change this value, add/put will ignore it |
|||||||||||||||||||||||||||||||||||||||||||
prefix |
string | prefix to be prepended for autogenerated columns: uuid, suuid, sfuuid |
|||||||||||||||||||||||||||||||||||||||||||
separator |
string | to be used as a separator in join or lists depending on the column properties |
|||||||||||||||||||||||||||||||||||||||||||
keyword |
boolean | store as is without tokenizing (ElasticSearch) |
|||||||||||||||||||||||||||||||||||||||||||
join |
Array.<string> | a list with property names that must be joined together before performing a db operation, it will use the given record to produce a new property, empty properties will be still joined as empty strings. |
|||||||||||||||||||||||||||||||||||||||||||
foreign |
object |
<optional> |
foreign key reference (SQL) Properties
|
||||||||||||||||||||||||||||||||||||||||||
convert |
object |
<optional> |
convert value on save Properties
|
||||||||||||||||||||||||||||||||||||||||||
check |
object | validation checks Properties
|
|||||||||||||||||||||||||||||||||||||||||||
sql |
string | Generic SQL specific instructions to apply when creating a table or column |
|||||||||||||||||||||||||||||||||||||||||||
sqlite |
string | Sqlite specific instructions to apply when creating a table or column |
|||||||||||||||||||||||||||||||||||||||||||
pg |
string | PostgreSQL specific instructions to apply when creating a table or column |
|||||||||||||||||||||||||||||||||||||||||||
dynamodb |
object | DynamoDB specific instructions to apply when creating a table or column |
|||||||||||||||||||||||||||||||||||||||||||
elasticsearch |
object | Elasticsearch specific instructions to apply when creating a table or column |
|||||||||||||||||||||||||||||||||||||||||||
api |
object | API access permisions Properties
|
Type:
- object
DbUser
- Description:
User instance of DbTableColumn
- Source:
Properties:
| Name | Type | Attributes | Description |
|---|---|---|---|
login |
string | primary key, user email, name or other unique identifier |
|
id |
string | unique auto-generated UUID |
|
name |
string | full user name |
|
roles |
Array.<string> | list of roles for access |
|
flags |
Array.<string> | custom tags |
|
ctime |
bigint | create time in milliseconds |
|
mtime |
bigint | last modified time, auto saved |
|
secret |
string | hashed user password |
|
expires |
gibint |
<optional> |
if set access will be defined if beyond this time |
pushkey |
string |
<optional> |
can be used for push notifications |
passkey |
string |
<optional> |
can be used for passkey verifications |
Type:
- object
Example
Default schema
{
login: {
primary: 1,
keyword: 1,
length: 140,
check: { max: 140 }
},
id: {
type: 'uuid',
prefix: 'u_',
unique: 1,
keyword: 1,
dynamodb: { projections: 'ALL' },
api: { pub: 1 }
},
name: {
type: 'text',
notempty: 1,
length: 140,
check: { max: 140 },
api: { pub: 1 }
},
roles: {
type: 'list',
keyword: 1,
convert: { list: 1, lower: 1 },
api: { internal: 1 }
},
flags: {
type: 'list',
keyword: 1,
length: 140,
check: { max: 140 },
convert: { list: 1 }
},
ctime: { type: 'now', readonly: 1 },
mtime: { type: 'now' },
secret: { type: 'text', check: { max: 140 }, api: { priv: 1 } },
expires: { type: 'bigint', api: { internal: 1, priv: 1 } },
pushkey: { type: 'text', api: { priv: 1 }, check: { max: 4096 } },
passkey: { type: 'text', api: { internal: 1, priv: 1 }, check: { max: 4096 } }
}