data-store¶
The data-store module allows you to manage entities which are serializable classes. It can store them and generate a final JSON file which contains all serializable information from the stored entities. You can also provide a JSON to the data-store and it will unserialize it and create the entities corresponding.
Using This Module¶
First add the module to your project:
npm install --save @obsidianjs/data-store
Then use it in your application (in your main index.js
):
const obsidian = require("@obsidianjs/obsidian");
const dataStore = require("@obsidianjs/data-store");
const app = obsidian("my-application");
app.use(dataStore);
app.start();
Finally require it in modules that need it:
{
name: "my-module",
requires: ["data-store"],
load(app) {
const {dataStore} = app.modules;
// ...
},
// ...
}
DataStore API¶
-
class
DataStore
()¶ Stores project’s entities and blobs.
-
DataStore.
addEntity
(entity, path="/")¶ Add an entity to the store.
Arguments: Returns: undefined –
-
DataStore.
clear
()¶ Clear the store (remove all entities and blobs stored in the data store).
Returns: undefined –
-
DataStore.
getEntity
(id)¶ Get an entity
Arguments: - id (string) – The entity ID.
Returns: Entity|undefined –
-
DataStore.
listEntities
(path="/**")¶ List entities that matches the given path. (e.g.:
"/"
,"/*"
"/models/*"
).Arguments: - path (string) – The path to list (accepts globing).
Returns: Array.<Entity> – An array of the matching entities.
-
DataStore.
removeEntity
(entity)¶ Remove an entity from the store.
Arguments: - entity (Entity|string) – The entity or its id
Returns: undefined –
-
DataStore.
serializeEntities
()¶ Serialize all stored entities.
Returns: Object – The serialized entities.
-
DataStore.
unserializeEntities
(serializedEntities)¶ Unserialize entities from given JSON (the unserialized entities are added to the store).
Arguments: - serializedEntities (string) – The entities serialized as JSON
Returns: undefined –
-