I've been doing an audit of all the parts of Iris that are directly using MongoDB to see if they can be generalised so that we can slot in a more general database layer that can be used with any database.
I'd love to get nedb support in core as it takes MongoDB syntax and doesn't require any database set up (just an npm install) which would be amazing for small sites. As a larger thing this would allow support for MySQL, PostgreSQL and whatever comes next. Even still supporting MongoDB it makes sense to do as much through an API as we can.
I'm going to go through to swap out every bit of code that calls MongoDB directly (aside from the core db.js and entity stuff which is step 2). Here's what I've found so far. I'm putting this out here so that people can add anything they've got in contributed modules or personal projects.
Lists module - Uses iris.dbCollections to list entity types and also extract the schema.
Schema UI - Gets lists of entity types.
EntityUI - Uses findOne directly from MongoDB on the edit page.
User module - Five findOne queries, four count queries and two direct updates.
Frontend - Lists entity types.
Paths module - Find and FindOne queries
Entity.js - List of types and type schema
Obviously entity_edit, entity_delete, entity_create, entity_fetch and db.js as well.
Solution:
iris.dbCollections should still list entity types and their schema so that it can be used as is.
The stored schema should be the JSON entity schema and not the Mongoose schema. We store both at the moment, just need to make sure we are using the JSON one.
Replace all find, findOne and count queries with the entity fetch hook. This is done in many places already, just needs changing in some core stuff.
Change all entity updates outside of the entity update file itself to trigger hooks (already existing) that call an entity update.
Once that's done the only MongoDB specific stuff will be in entity_edit, entity_delete, entity_create, entity_fetch and db.js. Hopefully it shouldn't be too difficult to wrap the final stages of these where the database stuff happens in hooks that depend on which database type is selected in config.
Feel free to add any thoughts. It's a major piece of work but hopefully possible without any breaking changes.
I've been doing an audit of all the parts of Iris that are directly using MongoDB to see if they can be generalised so that we can slot in a more general database layer that can be used with any database.
I'd love to get nedb support in core as it takes MongoDB syntax and doesn't require any database set up (just an npm install) which would be amazing for small sites. As a larger thing this would allow support for MySQL, PostgreSQL and whatever comes next. Even still supporting MongoDB it makes sense to do as much through an API as we can.
I'm going to go through to swap out every bit of code that calls MongoDB directly (aside from the core db.js and entity stuff which is step 2). Here's what I've found so far. I'm putting this out here so that people can add anything they've got in contributed modules or personal projects.
iris.dbCollections
to list entity types and also extract the schema.Obviously
entity_edit
,entity_delete
,entity_create
,entity_fetch
anddb.js
as well.Solution:
iris.dbCollections
should still list entity types and their schema so that it can be used as is.Once that's done the only MongoDB specific stuff will be in
entity_edit
,entity_delete
,entity_create
,entity_fetch
anddb.js
. Hopefully it shouldn't be too difficult to wrap the final stages of these where the database stuff happens in hooks that depend on which database type is selected in config.Feel free to add any thoughts. It's a major piece of work but hopefully possible without any breaking changes.