the docs for what i just did
Former-commit-id: 1c241c331cbc1b3d05a8add5ce9e0899b709a712
This commit is contained in:
@@ -204,13 +204,13 @@
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Database.html">Database</a></li><li><a href="Model.html">Model</a></li></ul>
|
||||
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Database.html">Database</a></li><li><a href="Model.html">Model</a></li></ul><h3>Global</h3><ul><li><a href="global.html#addModel">addModel</a></li><li><a href="global.html#model">model</a></li><li><a href="global.html#property">property</a></li><li><a href="global.html#resolveDependants">resolveDependants</a></li><li><a href="global.html#syncModels">syncModels</a></li></ul>
|
||||
</nav>
|
||||
|
||||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Fri Feb 11 2022 15:12:15 GMT+0000 (Greenwich Mean Time)
|
||||
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Sat Feb 12 2022 03:04:16 GMT+0000 (Greenwich Mean Time)
|
||||
</footer>
|
||||
|
||||
<script> prettyPrint(); </script>
|
||||
|
||||
105
jsdoc/Model.html
105
jsdoc/Model.html
@@ -28,7 +28,7 @@
|
||||
|
||||
<header>
|
||||
|
||||
<h2><span class="attribs"><span class="type-signature"></span></span>Model<span class="signature">()</span><span class="type-signature"></span></h2>
|
||||
<h2><span class="attribs"><span class="type-signature"></span></span>Model<span class="signature">(name, properties, dummy)</span><span class="type-signature"></span></h2>
|
||||
|
||||
<div class="class-description"><p>The Model class is used to create a model instance.</p></div>
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="Model"><span class="type-signature"></span>new Model<span class="signature">()</span><span class="type-signature"></span></h4>
|
||||
<h4 class="name" id="Model"><span class="type-signature"></span>new Model<span class="signature">(name, properties, dummy)</span><span class="type-signature"></span></h4>
|
||||
|
||||
|
||||
|
||||
@@ -60,6 +60,101 @@
|
||||
|
||||
|
||||
|
||||
<h5>Parameters:</h5>
|
||||
|
||||
|
||||
<table class="params">
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
<th>Name</th>
|
||||
|
||||
|
||||
<th>Type</th>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<th class="last">Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="name"><code>name</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type">string</span>
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<td class="description last"><p>The name of the model</p></td>
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="name"><code>properties</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type">object</span>
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<td class="description last"><p>The properties of the model</p></td>
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="name"><code>dummy</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type">boolean</span>
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<td class="description last"><p>Whether or not the model is a dummy model</p></td>
|
||||
</tr>
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -93,7 +188,7 @@
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="model.js.html">model.js</a>, <a href="model.js.html#line2">line 2</a>
|
||||
<a href="model.js.html">model.js</a>, <a href="model.js.html#line4">line 4</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
@@ -155,13 +250,13 @@
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Database.html">Database</a></li><li><a href="Model.html">Model</a></li></ul>
|
||||
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Database.html">Database</a></li><li><a href="Model.html">Model</a></li></ul><h3>Global</h3><ul><li><a href="global.html#addModel">addModel</a></li><li><a href="global.html#model">model</a></li><li><a href="global.html#property">property</a></li><li><a href="global.html#resolveDependants">resolveDependants</a></li><li><a href="global.html#syncModels">syncModels</a></li></ul>
|
||||
</nav>
|
||||
|
||||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Fri Feb 11 2022 15:12:15 GMT+0000 (Greenwich Mean Time)
|
||||
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Sat Feb 12 2022 03:04:16 GMT+0000 (Greenwich Mean Time)
|
||||
</footer>
|
||||
|
||||
<script> prettyPrint(); </script>
|
||||
|
||||
@@ -28,9 +28,9 @@
|
||||
<article>
|
||||
<pre class="prettyprint source linenums"><code>const Logger = require('../../logger.js');
|
||||
const DataTypes = require('./types.js');
|
||||
const DataConstraints = require('./relationships_constraints.js');
|
||||
const Model = require('./model.js');
|
||||
|
||||
|
||||
/**
|
||||
* In order to keep the models dynamic and flexible, we need to be able to add
|
||||
* new models to the database in whatever order the developer wants too. Without
|
||||
@@ -50,28 +50,133 @@ class PSQLObjectRelation {
|
||||
Logger.Database('ORM Loading...');
|
||||
this.connection = psqlConnection;;
|
||||
this.models = [];
|
||||
// dummyModels are for models that have requested a model that doesn't exist
|
||||
// the model that doesn't exist will be added here, and once it is added, the
|
||||
// dummy dependancy will be resolved
|
||||
this.dummyModels = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @function model
|
||||
* @description Gets a model from the database stash
|
||||
* @param {string} modelName - The name of the target model
|
||||
*/
|
||||
model(modelName) {
|
||||
return { }
|
||||
// TODO: Resolve the dependancy if it dosen't exist and make a note of it
|
||||
if (!this.models[modelName]) {
|
||||
Logger.Database(`Model ${modelName} does not exist, adding to dummyModels`);
|
||||
|
||||
if (this.dummyModels[modelName]) {
|
||||
return this.dummyModels[modelName];
|
||||
}
|
||||
|
||||
const dummy = new Model(modelName, {}, true);
|
||||
this.dummyModels[modelName] = dummy;
|
||||
return dummy;
|
||||
}
|
||||
return this.models[modelName];
|
||||
}
|
||||
|
||||
addModel(name, model, constraints) {
|
||||
/**
|
||||
* @function addModel
|
||||
* @description Adds a model to the database stash
|
||||
* @param {string} name
|
||||
* @param {object} model
|
||||
*/
|
||||
addModel(name, model) {
|
||||
Logger.Database(`ORM Adding ${name}`);
|
||||
|
||||
if (this.models[name]) {
|
||||
Logger.Error(`Redefinition of model ${name}, ignoring.`);
|
||||
return;
|
||||
}
|
||||
|
||||
const keys = Object.keys(model);
|
||||
this.models[name] = new Model;
|
||||
|
||||
/**
|
||||
* Make sure that every property has a type and a conatraints array
|
||||
* If not, add it
|
||||
* The structure should always look like:
|
||||
* property: {
|
||||
* type: DataTypes.VARCHAR(50),
|
||||
* constraints: [ DataConstraints.PRIMARY_KEY, DataConstraints.NOT_NULL ]
|
||||
* }
|
||||
*/
|
||||
keys.forEach(key => {
|
||||
if (typeof model[key] != 'object') {
|
||||
const type = model[key];
|
||||
model[key] = {
|
||||
type: type,
|
||||
constraints: []
|
||||
};
|
||||
}
|
||||
if (!model[key].constraints) {
|
||||
model[key].constraints = [];
|
||||
}
|
||||
});
|
||||
|
||||
this.models[name] = new Model(name, model);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function resolveDependants
|
||||
* @description Resolves all the dependancies for the models that have been added where properties weren't available when they were added
|
||||
*/
|
||||
// TODO: Make this more maintainable
|
||||
resolveDepends() {
|
||||
|
||||
for (const dummyModelName in this.dummyModels)
|
||||
{
|
||||
const dummyModel = this.dummyModels[dummyModelName];
|
||||
|
||||
if (!this.models[dummyModel.name]) {
|
||||
Logger.Error(`Model ${dummyModel.name} does not exist, cannot resolve dependancies`);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const propertyName in dummyModel.properties)
|
||||
{
|
||||
const property = dummyModel.properties[propertyName];
|
||||
|
||||
if (property.type !== DataTypes.INHERET) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (property.referers.length === 0 || property.referers[0] === '') {
|
||||
Logger.Error(`Model ${dummyModel.name} has a property ${propertyName} with no referers`);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const referer of property.referers) {
|
||||
if (!this.models[referer]) {
|
||||
Logger.Error(`Model ${dummyModel.name} has a property ${propertyName} with a referer ${referer} that does not exist`);
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: Make more generic
|
||||
const relaventConstraints = this.models[referer].properties[dummyModelName].constraints;
|
||||
for (const constraint in relaventConstraints) {
|
||||
if (typeof relaventConstraints[constraint] === 'object') {
|
||||
this.models[referer].properties[dummyModelName].constraints[constraint] = DataConstraints.FOREIGN_KEY_REF(dummyModel.name);
|
||||
Logger.Database(`Model ${referer} has a property ${dummyModel.name} which was resolved to a foreign key`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.dummyModels.splice(this.dummyModels.indexOf(dummyModel), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ONLY run this after all models are properly added
|
||||
/**
|
||||
* @function syncModels
|
||||
* @description Syncs the models to the database
|
||||
* ONLY run this after all models are properly added
|
||||
*/
|
||||
async syncModels() {
|
||||
Logger.Database('ORM Syncing...');
|
||||
|
||||
this.resolveDepends();
|
||||
console.log(this.models['lego_brick']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,13 +191,13 @@ module.exports = PSQLObjectRelation;
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Database.html">Database</a></li><li><a href="Model.html">Model</a></li></ul>
|
||||
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Database.html">Database</a></li><li><a href="Model.html">Model</a></li></ul><h3>Global</h3><ul><li><a href="global.html#addModel">addModel</a></li><li><a href="global.html#model">model</a></li><li><a href="global.html#property">property</a></li><li><a href="global.html#resolveDependants">resolveDependants</a></li><li><a href="global.html#syncModels">syncModels</a></li></ul>
|
||||
</nav>
|
||||
|
||||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Fri Feb 11 2022 15:12:15 GMT+0000 (Greenwich Mean Time)
|
||||
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Sat Feb 12 2022 03:04:16 GMT+0000 (Greenwich Mean Time)
|
||||
</footer>
|
||||
|
||||
<script> prettyPrint(); </script>
|
||||
|
||||
740
jsdoc/global.html
Normal file
740
jsdoc/global.html
Normal file
@@ -0,0 +1,740 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>JSDoc: Global</title>
|
||||
|
||||
<script src="scripts/prettify/prettify.js"> </script>
|
||||
<script src="scripts/prettify/lang-css.js"> </script>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
||||
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="main">
|
||||
|
||||
<h1 class="page-title">Global</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<section>
|
||||
|
||||
<header>
|
||||
|
||||
<h2></h2>
|
||||
|
||||
|
||||
</header>
|
||||
|
||||
<article>
|
||||
<div class="container-overview">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h3 class="subsection-title">Methods</h3>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="addModel"><span class="type-signature"></span>addModel<span class="signature">(name, model)</span><span class="type-signature"></span></h4>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="description">
|
||||
<p>Adds a model to the database stash</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h5>Parameters:</h5>
|
||||
|
||||
|
||||
<table class="params">
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
<th>Name</th>
|
||||
|
||||
|
||||
<th>Type</th>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<th class="last">Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="name"><code>name</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type">string</span>
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<td class="description last"></td>
|
||||
</tr>
|
||||
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="name"><code>model</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type">object</span>
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<td class="description last"></td>
|
||||
</tr>
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="entity-relationships.js.html">entity-relationships.js</a>, <a href="entity-relationships.js.html#line52">line 52</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="model"><span class="type-signature"></span>model<span class="signature">(modelName)</span><span class="type-signature"></span></h4>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="description">
|
||||
<p>Gets a model from the database stash</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h5>Parameters:</h5>
|
||||
|
||||
|
||||
<table class="params">
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
<th>Name</th>
|
||||
|
||||
|
||||
<th>Type</th>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<th class="last">Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="name"><code>modelName</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type">string</span>
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<td class="description last"><p>The name of the target model</p></td>
|
||||
</tr>
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="entity-relationships.js.html">entity-relationships.js</a>, <a href="entity-relationships.js.html#line31">line 31</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="property"><span class="type-signature"></span>property<span class="signature">(name)</span><span class="type-signature"></span></h4>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="description">
|
||||
<p>Gets a property from the model</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h5>Parameters:</h5>
|
||||
|
||||
|
||||
<table class="params">
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
<th>Name</th>
|
||||
|
||||
|
||||
<th>Type</th>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<th class="last">Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="name"><code>name</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type">string</span>
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<td class="description last"><p>The name of the target property</p></td>
|
||||
</tr>
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="model.js.html">model.js</a>, <a href="model.js.html#line23">line 23</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="resolveDependants"><span class="type-signature"></span>resolveDependants<span class="signature">()</span><span class="type-signature"></span></h4>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="description">
|
||||
<p>Resolves all the dependancies for the models that have been added where properties weren't available when they were added</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="entity-relationships.js.html">entity-relationships.js</a>, <a href="entity-relationships.js.html#line93">line 93</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="syncModels"><span class="type-signature"></span>syncModels<span class="signature">()</span><span class="type-signature"></span></h4>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="description">
|
||||
<p>Syncs the models to the database
|
||||
ONLY run this after all models are properly added</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<a href="entity-relationships.js.html">entity-relationships.js</a>, <a href="entity-relationships.js.html#line143">line 143</a>
|
||||
</li></ul></dd>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Database.html">Database</a></li><li><a href="Model.html">Model</a></li></ul><h3>Global</h3><ul><li><a href="global.html#addModel">addModel</a></li><li><a href="global.html#model">model</a></li><li><a href="global.html#property">property</a></li><li><a href="global.html#resolveDependants">resolveDependants</a></li><li><a href="global.html#syncModels">syncModels</a></li></ul>
|
||||
</nav>
|
||||
|
||||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Sat Feb 12 2022 03:04:16 GMT+0000 (Greenwich Mean Time)
|
||||
</footer>
|
||||
|
||||
<script> prettyPrint(); </script>
|
||||
<script src="scripts/linenumber.js"> </script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -50,13 +50,13 @@
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Database.html">Database</a></li><li><a href="Model.html">Model</a></li></ul>
|
||||
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Database.html">Database</a></li><li><a href="Model.html">Model</a></li></ul><h3>Global</h3><ul><li><a href="global.html#addModel">addModel</a></li><li><a href="global.html#model">model</a></li><li><a href="global.html#property">property</a></li><li><a href="global.html#resolveDependants">resolveDependants</a></li><li><a href="global.html#syncModels">syncModels</a></li></ul>
|
||||
</nav>
|
||||
|
||||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Fri Feb 11 2022 15:12:15 GMT+0000 (Greenwich Mean Time)
|
||||
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Sat Feb 12 2022 03:04:16 GMT+0000 (Greenwich Mean Time)
|
||||
</footer>
|
||||
|
||||
<script> prettyPrint(); </script>
|
||||
|
||||
@@ -26,16 +26,49 @@
|
||||
|
||||
<section>
|
||||
<article>
|
||||
<pre class="prettyprint source linenums"><code>
|
||||
<pre class="prettyprint source linenums"><code>const Logger = require('../../logger.js');
|
||||
const DataTypes = require('./types.js');
|
||||
|
||||
/**
|
||||
* @class Model
|
||||
* @classdesc The Model class is used to create a model instance.
|
||||
* @param {string} name - The name of the model
|
||||
* @param {object} properties - The properties of the model
|
||||
* @param {boolean} dummy - Whether or not the model is a dummy model
|
||||
*/
|
||||
class Model {
|
||||
constructor(name, properties, dummy = false) {
|
||||
this.name = name;
|
||||
this.properties = properties;
|
||||
this.dummy = dummy;
|
||||
|
||||
constructor() {
|
||||
if (dummy)
|
||||
Logger.Database(`Model ${name} is dummy: ${dummy}`);
|
||||
|
||||
Logger.Database(`Model ${name} created, with properties: ${JSON.stringify(properties)}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @function property
|
||||
* @description Gets a property from the model
|
||||
* @param {string} name - The name of the target property
|
||||
*/
|
||||
property(name, referer = "") {
|
||||
if (this.dummy)
|
||||
{
|
||||
if (this.properties[name]) {
|
||||
this.properties[name].referers.push(referer);
|
||||
}
|
||||
this.properties[name] = {
|
||||
type: DataTypes.INHERET,
|
||||
referers: [referer],
|
||||
constraints: [],
|
||||
dummy: true
|
||||
}
|
||||
return "UNRESOVLED PROPERTY";
|
||||
}
|
||||
return this.property[name];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Model;
|
||||
@@ -49,13 +82,13 @@ module.exports = Model;
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Database.html">Database</a></li><li><a href="Model.html">Model</a></li></ul>
|
||||
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Database.html">Database</a></li><li><a href="Model.html">Model</a></li></ul><h3>Global</h3><ul><li><a href="global.html#addModel">addModel</a></li><li><a href="global.html#model">model</a></li><li><a href="global.html#property">property</a></li><li><a href="global.html#resolveDependants">resolveDependants</a></li><li><a href="global.html#syncModels">syncModels</a></li></ul>
|
||||
</nav>
|
||||
|
||||
<br class="clear">
|
||||
|
||||
<footer>
|
||||
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Fri Feb 11 2022 15:12:15 GMT+0000 (Greenwich Mean Time)
|
||||
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.10</a> on Sat Feb 12 2022 03:04:16 GMT+0000 (Greenwich Mean Time)
|
||||
</footer>
|
||||
|
||||
<script> prettyPrint(); </script>
|
||||
|
||||
Reference in New Issue
Block a user