final-orm
Version:
> Please check out https://github.com/oknoah/final and https://github.com/oknoah/final/packages/arangolize for similar projects that MAY be more up to date
59 lines (46 loc) • 1.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _model = require('./model');
var _model2 = _interopRequireDefault(_model);
var _edgeSchema = require('../schemas/edgeSchema');
var _edgeSchema2 = _interopRequireDefault(_edgeSchema);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class Edge extends _model2.default {
static _getSchema() {
if (!this._normalSchema) {
this._normalSchema = new _edgeSchema2.default(this.schema);
}
return this._normalSchema;
}
static _getDocument(documentHandle) {
return this._call('edge', documentHandle);
}
static async _getCollection() {
if (this._collection) {
return this._collection;
}
const db = await this._getDatabase();
const edge = db.edgeCollection(this.name);
try {
await edge.create();
await this._setIndexes(edge);
} catch (e) {}
return this._collection = edge;
}
static async add(from, to, data = {}) {
this._validate(data);
data = this._modelToDocument(data);
data._removed = false;
data.createdAt = new Date().toISOString();
data._from = typeof from === 'object' ? from._id : from;
data._to = typeof to === 'object' ? to._id : to;
const documentHandle = await this._call('save', data);
const document = await this._call('edge', documentHandle);
return this._createModelByDocument(document);
}
}
exports.default = Edge;
Edge._normalSchema = null;
Edge._collection = null;