mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-09 07:25:21 +02:00
Added aliases collection
This commit is contained in:
parent
2364fd2ea2
commit
40cd1f5a5e
3 changed files with 18 additions and 9 deletions
|
@ -1,4 +1,5 @@
|
||||||
const {pages: db} = require('../utils/database/index');
|
const {pages: pagesDb} = require('../utils/database/index');
|
||||||
|
const {aliases: aliasesDb} = require('../utils/database/index');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} PageData
|
* @typedef {Object} PageData
|
||||||
|
@ -27,7 +28,7 @@ class Page {
|
||||||
* @returns {Promise<Page>}
|
* @returns {Promise<Page>}
|
||||||
*/
|
*/
|
||||||
static async get(_id) {
|
static async get(_id) {
|
||||||
const data = await db.findOne({_id});
|
const data = await pagesDb.findOne({_id});
|
||||||
|
|
||||||
return new Page(data);
|
return new Page(data);
|
||||||
}
|
}
|
||||||
|
@ -39,7 +40,7 @@ class Page {
|
||||||
* @returns {Promise<Page[]>}
|
* @returns {Promise<Page[]>}
|
||||||
*/
|
*/
|
||||||
static async getAll(query = {}) {
|
static async getAll(query = {}) {
|
||||||
const docs = await db.find(query);
|
const docs = await pagesDb.find(query);
|
||||||
|
|
||||||
return Promise.all(docs.map(doc => new Page(doc)));
|
return Promise.all(docs.map(doc => new Page(doc)));
|
||||||
}
|
}
|
||||||
|
@ -115,7 +116,7 @@ class Page {
|
||||||
* @returns {Promise<Page>}
|
* @returns {Promise<Page>}
|
||||||
*/
|
*/
|
||||||
get parent() {
|
get parent() {
|
||||||
return db.findOne({_id: this._parent})
|
return pagesDb.findOne({_id: this._parent})
|
||||||
.then(data => new Page(data));
|
.then(data => new Page(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +126,7 @@ class Page {
|
||||||
* @returns {Promise<Page[]>}
|
* @returns {Promise<Page[]>}
|
||||||
*/
|
*/
|
||||||
get children() {
|
get children() {
|
||||||
return db.find({parent: this._id})
|
return pagesDb.find({parent: this._id})
|
||||||
.then(data => data.map(page => new Page(page)));
|
.then(data => data.map(page => new Page(page)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,11 +137,11 @@ class Page {
|
||||||
*/
|
*/
|
||||||
async save() {
|
async save() {
|
||||||
if (!this._id) {
|
if (!this._id) {
|
||||||
const insertedRow = await db.insert(this.data);
|
const insertedRow = await pagesDb.insert(this.data);
|
||||||
|
|
||||||
this._id = insertedRow._id;
|
this._id = insertedRow._id;
|
||||||
} else {
|
} else {
|
||||||
await db.update({_id: this._id}, this.data);
|
await pagesDb.update({_id: this._id}, this.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
@ -152,7 +153,7 @@ class Page {
|
||||||
* @returns {Promise<Page>}
|
* @returns {Promise<Page>}
|
||||||
*/
|
*/
|
||||||
async destroy() {
|
async destroy() {
|
||||||
await db.remove({_id: this._id});
|
await pagesDb.remove({_id: this._id});
|
||||||
|
|
||||||
delete this._id;
|
delete this._id;
|
||||||
|
|
||||||
|
|
6
src/utils/database/aliases.js
Normal file
6
src/utils/database/aliases.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
const Datastore = require('nedb');
|
||||||
|
const config = require('../../../config');
|
||||||
|
|
||||||
|
const db = new Datastore({filename: `./${config.database}/aliases.db`, autoload: true});
|
||||||
|
|
||||||
|
module.exports = db;
|
|
@ -1,4 +1,5 @@
|
||||||
const pages = require('./pages');
|
const pages = require('./pages');
|
||||||
|
const aliases = require('./aliases');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class Database
|
* @class Database
|
||||||
|
@ -142,5 +143,6 @@ class Database {
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
class: Database,
|
class: Database,
|
||||||
pages: new Database(pages)
|
pages: new Database(pages),
|
||||||
|
aliases: new Database(aliases)
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue