
WatermelonDB, a database for React and React Native apps - jinqueeny
https://github.com/Nozbe/WatermelonDB
======
bufferoverflow
Why not use SQLite directly instead of this extra layer?

~~~
radex
SQLite gives you just the "data fetching" part. But if you're building a
React/RN app, you probably also want everything to be automatically
observable.

For example, if you have a todo app, and you mark a task as done, you'd want
the task component to re-render, the list to re-render (put the task at the
bottom), and update the right counters (the counter of all tasks, and a
counter of all tasks in ta project), etc. I hope you're getting the point.

Watermelon is an observable abstraction on top of SQLite (or an arbitrary
database), so that you can connect data to components and have them update
automatically

~~~
nepeckman
So is it fair to say its a React specific ORM, that automatically makes the
mapped objects observable (an OORM, if you will)? Just trying to understand
the level of abstraction that you're going for.

~~~
radex
That's a fair description, yeah!

------
victorbojica
Isn't 10,000's of records a bit to low for a database ?

~~~
radex
A mobile app database. It can probably scale to hundreds of thousands too, but
very few apps and very few users of such apps would actually have THAT much
data.

The point is that most current solutions for React Native apps start being
super slow when you get to 1000s, or have other issues (like using SQLite
directly doesn't give you observability)

------
pmiri
This looks really good, actually. Having used SQLite, I waited a long time for
a good, functional, easily-debuggable DB for React Native.

Realm didn't cut it on the debugging part.

~~~
radex
I'll be really curious to hear your feedback on GH if you try it. We've been
using it internally in dev for a year, but we've just released this as open
source, so there's probably a ton to improve on.

------
barrystaes
When SQLite is not available in the browser, can it fallback to using use an
Adapter which just implements a (low performance) DB in memory or storage?

edit: link to Adapter docs
[https://github.com/Nozbe/WatermelonDB/blob/master/docs/Imple...](https://github.com/Nozbe/WatermelonDB/blob/master/docs/Implementation/Adapters.md)

~~~
radex
Yep, if you can support some (relatively basic) queries, and CRUD operations,
you can plug in essentially any database, and bridge on any platform. Think
Electron, SQLite on native macOS, heck, you could use Realm as the underlying
database if you so preferred...

------
kgraves
How does WatermelonDB compare to Realm?

~~~
radex
I'm not an expert at Realm, so I might get some details wrong, but briefly:

\- You can't run Realm on the web (not as a database, offline), but you can
with Watermelon

\- Realm is _a_ database, Watermelon is a more universal database framework
that can be backed by any underlying database via an adapter

\- Realm is more than just a database, it's also a whole app development
platform. And it's designed to sync with a proprietary Realm cloud service.
Watermelon is just a local database, but it tracks changes in the database so
you can plug it in and synchronize with an arbitrary backend

\- I heard that Realm (on React Native at least) doesn't perform super well
when you get to many thousands/tens of thousands of records, but i haven't
tested it yet myself, so take it with a grain of salt. Watermelon always does
lazy loading so it doesn't really affect performance how many records total
there are.

------
pvinis
Would this work as a kind of 'rxjs-persist', similar to 'redux-persist'?

------
lux
Looks like an awesome abstraction layer!

I'm curious how this would handle syncing like Gun
([https://gun.eco/](https://gun.eco/)), and an example of how it might work
with Vue.

~~~
radex
Not familiar with either Gun or Vue. I'll look into the former, and as for the
latter — Watermelon does not _actually_ depend on React. If one can supply a
way to hook an RxJS observable into Vue (a la higher order components in
React), it should work perfectly fine. Pull requests welcome!

------
GutenYe
Looks like it's just an ORM for SQLite. Isn't SQLite too large to be included
in the web?

~~~
radex
Yeah :/ There used to be this thing called Web SQL (which really… was SQLite)…
but… people didn't like it and it didn't catch on. So on the web, Watermelon
uses LokiJS, which isn't perfect, but still works well.

~~~
aikah
> but… people didn't like it and it didn't catch on.

Mozilla didn't like, developers liked it. Mozilla's excuse was "which SQL
spec?" which could have been solved with a bit of work. Same as the File
System API proposals by google. I'm sorry but indexed-db is not a replacement
for these 2. indexed-db is slow and inefficient when it comes to data storage
and is horrible to query.

~~~
invaliduser
IndexedDB used to be slow, but is it still yet? Not so sure, performance does
not seem that bad (see [http://reyesr.github.io/html5-storage-
benchmark/](http://reyesr.github.io/html5-storage-benchmark/) ) Do you have
some benchmark that shows it is indeed slow as of today?

------
pcmaffey
Great work, reminds me of minimongo. Any plans to make it easier to sync with
a server db?

~~~
radex
Yes! Planning to release a few helper functions and document exactly what the
procedure is to synchronize with a server. Internally, we know it works.

------
wasd
Would it be possible to write an adapter to use this with postgresql on the
web?

~~~
radex
It's possible, but Watermelon is specifically designed to be a local database,
not meant to run on a server.

------
nad7vx
can I use this in conjunction with graphQL and middleware such as apollo
client? so essentially, use the middleware to query my DB and use watermelon
for local storage?

~~~
radex
not very familiar with apollo, but I don't see why not. But just be aware that
Watermelon works best as a full local database copy (that synchronizes with
the server), not just a cache.

------
thomasfedb
The killer feature, quite understandably absent, is sync.

~~~
radex
See:
[https://news.ycombinator.com/item?id=17960347](https://news.ycombinator.com/item?id=17960347)

Sync is mostly there, but undocumented :/ Coming soon…

~~~
thomasfedb
In academia we say "not published, not done". Perhaps the open-source
community could benefit from "not documented, not done".

~~~
radex
You’re not wrong

~~~
thomasfedb
But am I right?

