CityWebConsultants / Iris

Modular content management and web application framework built with Node.js and MongoDB
http://irisjs.org
Other
9 stars 7 forks source link

Database abstraction layer #276

Closed FilipNest closed 8 years ago

FilipNest commented 8 years ago

Part of issue #274 (MongoDB decoupling)

See comment below for the latest/best explanation.

Doing this early on as it needs lots of testing and will make the second stage of the database decoupling task a lot easier.

I've gone through and replaced calls to Mongoose collections (find,update,count,get entity types) with the relevant hooks.

I've also renamed iris.dbSchemaConfig to iris.entityTypes which should now be the main way of getting a list of entity types and their schema. Instead of iris.dbSchemaConfig or iris.dbCollections. I've replaced all uses of these.

I did tests on functionality I replaced but if someone could re-test it'd be very useful. Particularly the one time login link stuff as that might be broken (I've haven't used that functionality yet).

There is one TODO regarding the API calls to get entityType schema as currently these schema don't show the fieldType information (just the name of the field type). Probably need to pull that in. The only places that use this are the two REST API queries in entity.js I think we used for the Drupal integration. If you're using these two API calls, let me know how and I'll try to get the iris.entityTypes structure to match that part as well. Worth looking into anyway now that we've got object fields, field collections and arrays of objects. This is now fixed.

FilipNest commented 8 years ago

Database abstraction layer

This is now done and seems to be working. Nothing in core should break if this is merged in and you shouldn't have to make any site changes (possible breakages in custom modules are described below with fixes).

There are certainly future improvements (https://www.npmjs.com/package/waterline was mentioned that could open up Iris to all major databases without us having to re-write the implementations) but the system can be expanded in the future now the API structure is in.

Even if we carry on using MongoDB for most projects, splitting the database-specific code out makes future development easier.

Possible breaking changes:

How it works:

nedb

nedb is a JavaScript only lightweight database that does most of its work in memory. It uses the same syntax as MongoDB. It handles persistence by storing the data in JSON files.

Main advantages (and why I think it should be in core as an option):

Have a go by putting the "dbEngine":"nedb" in a site's config.

One really good use case for it is testing as not requiring a MongoDB setup may make a lot of tests easier to run. Tests could just delete the database files when finished.

FilipNest commented 8 years ago

Have a look at what the hook error is the logs please. Just sorting out merge conflicts on this as your recent merge to db.js needs putting in.

facascante commented 8 years ago

i deleted the comment sorry i found out the cause of the hook error, it's because again of a new fieldtype that does not exist on your branch.

FilipNest commented 8 years ago

I've now merged in so could you retest?

facascante commented 8 years ago

can you also merge to the latest pr#280 which already in develop