rdbms-models
v1.0.5
Published
## Overview
Downloads
3
Readme
rdbms-models
Overview
rdbms-models
is a framework that allows you to derive model classes from a MySQL database schema.
We provide four classes (Database
, Table
, Column
, and Model
).
The Database
class is instantiated by passing in MySQL connection info, and then it fetches the tables and the columns (as a collection of Table
, each of which contains of collection of Column
) so you end up with a full javascript representation of your database schema, without the data.
The Model
class is a base class which is meant to be extended into other classes. Think of a Model
class as a Table
with custom joins to other tables. These custom joins can be hardcoded, or better yet, you can define a rule to join all tables that match a certain criteria (for example, you can join all child tables or all foreign tables, etc).
The days of manually joining tables together in your application are over. Enjoy the ease of using this framework to reduce code building classes or REST APIs to fetch data from your database.
Database
, Table
, and Column
class
For all intents and purposes, a Database
is a collection of tables, and a Table
is a collection of columns. Database
, Table
, and Column
may store metadata information as well.
The main purpose of these classes is so that we can fetch the database's schema and use it inside of a Model
class.
You instantiate a Database class like so:
var db = new Database("localhost","root","password","databaseName");
db.init();
The constructor will simply instantiate the database object, and init
will fetch all of the tables, columns, and other necessary data related to the schema of the database.
By the end, you will have a Database
which has a collection of Table
, each of which has a collection of Column
. Each Table
will have it's primary keys and it's foreign keys made available, and if columns are foreign keys, it will be made available what columns they reference.
Model Class
It could be that we give an instance Table
the power to fetch rows, so that articleTable.fetch(id)
would return a table row from the article table. But, what if you want to join your table with another?
Models allow you to configure a table with a join and make it reusable across your application.