Models are essential to persisting data, which almost any application needs. Since ike is built on Javascript, it makes sense to focus on non-relational databases first.
The first one we're attacking is CouchDB and its super-saiyan counterpart Cloudant. Both will have a dedicated model for persisting and retrieving data.
Basic information
The model will be called Kubus, which is a type of couch.
Should, as always, drink as much as possible from Rails.
Smart defaults, configurable if needed.
Model validation and simple error handling.
Database views
Views are design documents specifically designed to retrieve information from the database.
Database views should all be in one folder, each one on its file. The ideal path is /app/dbviews/. There can be folders inside dbviews, but only on very specific cases.
Each file will be named as filename.view.js.
A view file should look like:
class SomeView extends KubusView {
constructor() {
this.viewName = 'someOtherName'; // Optional, default would be class name
}
map(doc) {
emit(doc.id, doc.balance);
}
reduce(key, values, rereduce) {
return sum(values);
}
}
Cloudant search indexes
Search indexes should be their own file type, and reside in a separate file (but within dbviews folder). The file should be name filenmame.search.js.
A search index file should look like:
class SomeSearchIndex extends KubusSeach {
constructor() {
this.viewName = 'someOtherName'; // Optional, default would be class name
}
map(doc) {
index('name', doc.name, {store: true});
}
}
To query a seach index, just use the method search:
Model superclass
Model classes are logical representations of the document, and the superclass should provide a foundation for building on top of.
class Some extends KubusModel {}
Document validation
Cloudant and CouchDB will accept any document, and it's the job of the application to ensure consistency. Having model validations will aid just that.
Edit and delete documents
Editing and deleting documents should be left to the instance, which will be able to know exaclty what to do with the document and its state.
Models are essential to persisting data, which almost any application needs. Since ike is built on Javascript, it makes sense to focus on non-relational databases first.
The first one we're attacking is CouchDB and its super-saiyan counterpart Cloudant. Both will have a dedicated model for persisting and retrieving data.
Basic information
Kubus
, which is a type of couch.Database views
Views are design documents specifically designed to retrieve information from the database.
/app/dbviews/
. There can be folders insidedbviews
, but only on very specific cases.filename.view.js
.A view file should look like:
Cloudant search indexes
Search indexes should be their own file type, and reside in a separate file (but within
dbviews
folder). The file should be namefilenmame.search.js
.A search index file should look like:
To query a seach index, just use the method search:
Database models
Model superclass Model classes are logical representations of the document, and the superclass should provide a foundation for building on top of.
Document validation Cloudant and CouchDB will accept any document, and it's the job of the application to ensure consistency. Having model validations will aid just that.
Easy document retrieval Getting documents should be easy enough, specially when I know exactly what I'm looking for.
Edit and delete documents Editing and deleting documents should be left to the instance, which will be able to know exaclty what to do with the document and its state.
Lifecycle events It should be possible to hook into a specific lifecycle point and perform actions. Main lifecycle events we should be looking into: