14 ms·
WatermelonDB, a database for React and React Native apps
- bufferoverflow 8y agoWhy not use SQLite directly instead of this extra layer?
- radex 8y agoSQLite 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 8y agoSo 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 8y agoThat's a fair description, yeah!
- amelius 8y agoDoes that mean that if user A makes an update to the database, then user B (on a different computer) will see the update?
- radex 8y agoNo, Watermelon is a local app database. But you can plug it into a sync engine to synchronize with the server (and then from the server to another device) — it's up to you
- jonnydubowsky 8y agoThanks for this concise example! This helped me to understand why I should try it out, and led me to demoing this myself. I'll report back my findings
- eyeos 8y agoBecause then you don’t get to reinvent the wheel.
- radex 8y agoIt's easy to be cynical on HN, but to the best of my knowledge, no other solution for React Native checks all the boxes we need. And it's not like reinventing the wheel (it still uses SQLite), more like inventing better suspenders for the whole undercarriage ;)
- cift 8y agoLooks like it's mostly to provide a lazy loading wrapper for SQLite to React
- tomhoward 8y agoBecause it's very cumbersome, interfacing between Javascript and SQLite, and mapping between database records and Javascript objects. And it doesn't easily fit with the React way of doing things without some library to abstract away all the wiring. I started building a hybrid mobile app (not React) with a large SQLite database about 4 years ago and have kept working on it ever since, and I've found the data storage aspect of the app very painful to maintain and extend. I'm now starting to rebuild it using React Native, and a storage plugin like this could be perfect. I'd been looking at Realm, but haven't gotten as far as committing to it yet, so I'll take a close look at WatermelonDB too.
- pknopf 8y agoI'm not buying the "too cumbersome to use SQLite" argument. This still seems like a large unnecessary abtraction.
- tomhoward 8y agoSincere question: do you much work in React/React Native with large SQLite databases or other large data stores? As the sibling (and better) comment[1] to my original comment points out, this library makes the data automatically observable throughout the React app, making it much simpler to update views in response to database changes. I can understand you might not understand the value of this if you hadn't done a lot of work with React apps that have large data sets and where data changes need to be reflected in multiple different views. [1] https://news.ycombinator.com/item?id=17958822 https://news.ycombinator.com/item?id=17958822
- anaganisk 8y agoWhy don't you try linking react with a large Sqlite, and later build a wrapper of your own, and then release it in HN next year as, pinappleDB?
- kgraves 8y agoHow does WatermelonDB compare to Realm?
- radex 8y agoI'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.
- barrystaes 8y agoWhen 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/Implementation/Adapters.md https://github.com/Nozbe/WatermelonDB/blob/master/docs/Imple...
- radex 8y agoYep, 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...
- pvinis 8y agoWould this work as a kind of 'rxjs-persist', similar to 'redux-persist'?
- tomp 8y agoI'm just waiting for someone to say how "racist" the name is.
- tEMporality7 8y agoHow is it racist?
- victorbojica 8y agoIsn't 10,000's of records a bit to low for a database ?
- radex 8y agoA 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)
- GutenYe 8y agoLooks like it's just an ORM for SQLite. Isn't SQLite too large to be included in the web?
- radex 8y agoYeah :/ 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 8y ago> 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.
- radex 8y agoAgreed! IDB is simpler in some ways, but having a real relational database is a lot better for many advanced applications — and also can be more easily used for porting to different platforms, since you can run SQLite on any native platform
- invaliduser 8y agoIndexedDB 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?
- detaro 8y agoWanting a specified query language for a database API isn't really an excuse IMHO. (and if it really were just "a bit of work", one has to ask why the proposers then didn't bother to just do that. As cool as sqlite is, tying browsers to a specific version of it seems questionable)
- ericnyamu 8y agoafter tanking a whole day to configure cockroachDB now i have to configure watermelonDB too ? lol.
- pmiri 8y agoThis 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 8y agoI'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.
- pcmaffey 8y agoGreat work, reminds me of minimongo. Any plans to make it easier to sync with a server db?
- radex 8y agoYes! Planning to release a few helper functions and document exactly what the procedure is to synchronize with a server. Internally, we know it works.
- thomasfedb 8y agoThe killer feature, quite understandably absent, is sync.
- radex 8y agoSee: https://news.ycombinator.com/item?id=17960347 https://news.ycombinator.com/item?id=17960347 Sync is mostly there, but undocumented :/ Coming soon…
- thomasfedb 8y agoIn academia we say "not published, not done". Perhaps the open-source community could benefit from "not documented, not done".
- radex 8y agoYou’re not wrong
- thomasfedb 8y agoBut am I right?
- lux 8y agoLooks 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 8y agoNot 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!
- wasd 8y agoWould it be possible to write an adapter to use this with postgresql on the web?
- radex 8y agoIt's possible, but Watermelon is specifically designed to be a local database, not meant to run on a server.
- nad7vx 8y agocan 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 8y agonot 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.