ponzu-cms / ponzu

Headless CMS with automatic JSON API. Featuring auto-HTTPS from Let's Encrypt, HTTP/2 Server Push, and flexible server framework written in Go.
https://docs.ponzu-cms.org
BSD 3-Clause "New" or "Revised" License
5.67k stars 387 forks source link

Custom databases #346

Closed richterk closed 4 years ago

richterk commented 4 years ago

I'm sorry I'm creating an issue on the board, and if I wasn't so lazy, I'd just go look in the code and see how you have data stores implemented, but I digress. If my company were to begin using Ponzu, we would want to hook it up to our MongoDB cloud cluster. How difficult would it be to switch out the datastore in Ponzu?

I did notice that it seems to be fairly easy to add something like this additionally via hooks, and I did see that you created a rough prototype for "live data" hooks in the live folder. Just wanted to get some experienced opinions, while I'm trying to make a decision about what we want to go with.

I'm really digging the design and layout of ponzu, overall.

olliephillips commented 4 years ago

I just answered another comment re datastore providers here, it might help :- https://github.com/ponzu-cms/ponzu/issues/213#issuecomment-628067632

In a nutshell, it's totally doable but will need community support. If you need it you build it sort of thing. You could get on the hooks, but really what Ponzu needs (if BoltDB isn't sufficient for the use case) is an interface abstraction of the datastore so that users can bring their own. That's not there ATM.

nilslice commented 4 years ago

Mongo would probably be one of the more straightforward translations from Ponzu's database implementation. Since Ponzu uses a key-value store, its "buckets" aren't far off from a schema/model you may use in Mongo.

I would recommend using the boltbrowser tool to inspect your Ponzu instance's system.db file. You'll need to shut down the ponzu server prior to inspecting, as the process using system.db obtains an exclusive lock on it.

You will notice that the top-level "buckets" (e.g. a bucket for each "content type" you create) map fairly well to Mongo collections. Where you may have some difficulty is that there is also a time-sorted copy of the database in buckets at the same level as the original buckets. I don't claim that this was the best implementation, but it solved a need I had at them time. This poses some difficulty if you're also trying to serve the Ponzu HTTP API from Mongo, since you'd probably need to do the sorting in the Mongo query to make the APIs consistent.

If you were to serve the Ponzu content from Mongo through a different API, then Ponzu's hooks might actually be a good place to start, rather than swapping the database implementation.

amjadniazi48 commented 4 years ago

At least you should provide the support of "Redis" key-value store. https://db-engines.com/en/system/BoltDB%3BRedis