-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.js
More file actions
40 lines (40 loc) · 1.38 KB
/
storage.js
File metadata and controls
40 lines (40 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var fs = require('fs');
var SchemaClass = require('./schema');
// Represents a persistent storage containing all time line entities
module.exports = function (path) {
// Path to the given storage
this._path = path;
// Creates a new schema in the current storage
this.create = function (schemaName, callback) {
var path = this._path + '/' + schemaName;
fs.mkdir(path, function (error) {
if (!error || (error && error.code === 'EEXIST')) {
callback();
} else {
callback(error);
}
});
};
// Lists all storage schemas
this.list = function (callback) {
var self = this;
fs.readdir(this._path, function (error, fileNames) {
if (undefined != error) {
callback(error);
return;
}
var schemas = [];
for (var i = 0; i < fileNames.length; i++) {
var fileName = fileNames[i];
var schema = new SchemaClass(self, fileName);
schemas.push(schema);
}
callback(undefined, schemas);
});
};
// Gets a schema from the current storage specified by the schema name
this.get = function (schemaName) {
var schema = new SchemaClass(this, schemaName);
return schema;
};
};