DbSchemaSource - do-/node-doix-db GitHub Wiki
DbSchemaSource
is a ModuleMap descendant used to fill in a DbSchema from source files.
Constructor
const myDbSchemaSource = new DbSchemaSource ({
schema,
root: '/opt/myProject', // or ['/opt/myProject', ...]
// filter: (str, arr) => arr.at (-2) === 'Model', // **/Model/*
// ext: '.js',
// merger: new myDbObjectMerger (someMergingOptions)
})
Options
Name | Type | Description |
---|---|---|
schema |
DbSchema | The schema this source is for |
root |
String or [String] |
Absolute path(s) to read sources from |
filter |
(String, Array) => Boolean |
An indicator function to filter relative paths (the 1st parameter is the path string, the 2nd is same string split by path separators) |
ext |
String |
File extension to check for (aside from filter ) |
merger |
ObjectMerger | An instance of custom object merger, in case when the default DbObjectMerger is not enough |
The root
, filter
and ext
options are passed to the ModuleLoader constructor.
Properties
Name | Type | Description |
---|---|---|
loader |
ModuleLoader | the directory scanner |
merger |
ObjectMerger | the object used to merge the content of equally named modules found in different directories |
Methods
load ()
This method scans through loader.requireAll ()
result and for each [name, module]
pair obtained:
- stores it by calling
set (name, module)
(with merging, see below); - emits the
'complete'
event by means ofmerger
for each existing entry; - finally calls
schema.add ()
for each resulting key-value pair.
set (key, value)
The standard set method is rewritten so for an existing key
, the new value
is merged
into the old one instead of overwriting it.
In this class, set
is called internally by load
and not intended for direct use.