Using RedwoodJS with LowDB

So I’m wondering what the possibility of using a JSON Database like LowDB GitHub - typicode/lowdb: Simple to use local JSON database. Powered by plain JavaScript (supports Node, Electron and the browser) together with RedwoodJS

Looking at the cookbooks a combination that I think should work is

Also, the example here that shows how to setup Redwood with faunadb seems to be a good option too How can I wire up a GraphQL API to RedwoodJS? - #5 by dblock

I’d appreciate any other ideas or thoughts on this

@koolamusic lowdb is a new one for me so thanks for making me away of it – i can think of some cases where it could be rather useful

So – this is without trying it – I have two thoughts:

1 - I bet you could get it to work in dev/local (or some other environment you control). Simply write your sdl by hand, create a service and instead of using the Prisma API use lowdb’s. This isn’t very unlike writing your own service and using any third party api to call Contentful, some other GraphQL service … or really anything else that returns data.

2 - It won’t really work because when you deploy (say to Netlify) you cannot write to it. Prisma cannot write to the SQLite database either when deployed. And even if you could write to the file, how would you persists changes on the next subsequent deploy?

2a) But for reads and just reads? Maybe it could. Depending on the size though you’d want to take care what is in the repo. You’d use the

const adapter = new FileAsync(‘db.json’)

since the api side cannot access localStorage.

And the file would likely have to live in the functions dir so it is zipped and shipped up on Netlify deploy.

Note if you just need to store (well, read and write it) JSON (without filtering it), Postgres (and Prisma) supports Json datatypes. I’m using some now and the parsed info comes right back in as a response to a gql query.

Note I see someone here has tried to use lowdb on Netlify but there use case was not so straightforward:

I could see once RW has page prerendering that lowdb could be a source of the data that makes pages on build, though.

Edit: read some issues on lowdb:

^^ might be an issue.


Hi Andrew! I also think this has super interesting potential. Especially since AWS Elastic File System now works with AWS Lambdas! This means serverless functions can now have storage :rocket:

Here’s an example I found of someone trying something similar with SQLite:

Cool, right?

So you’d need to deploy directly to AWS Lamdba, which is also now possible.

Keep us posted if you give this a go!

1 Like