rxdb | A fast , offline-first , reactive Database for JavaScript | Database library
kandi X-RAY | rxdb Summary
kandi X-RAY | rxdb Summary
RxDB (short for Reactive Database) is a NoSQL-database for JavaScript Applications like Websites, hybrid Apps, Electron-Apps, Progressive Web Apps and Node.js. Reactive means that you can not only query the current state, but subscribe to all state changes like the result of a query or even a single field of a document. This is great for UI-based realtime applications in way that makes it easy to develop and also has great performance benefits. To replicate data between your clients and server, RxDB provides modules for realtime replication with any CouchDB compliant endpoint and also with custom GraphQL endpoints.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of rxdb
rxdb Key Features
rxdb Examples and Code Snippets
import { addRxPlugin } from 'rxdb'
import rxdbSearch from 'rxdb-search'
addRxPlugin(rxdbSearch)
...
const { RESULT, RESULT_LENGTH } = await collection.search(query: string, siQUERYoptions ?: {})
console.log(RESULT)
/*
`collection.search` is just
Community Discussions
Trending Discussions on rxdb
QUESTION
We are using react-naive-sqlite-2
in our application with RxDB
and started getting this error somewhat sporadically. It seems to happen after we remove the database. I was surprised to see this was a WebSQL
error since we are using react-native and WebSQL
is deprecated. I don't have great ways to debug this but my hunch is that we have some code that still tries to access the now dead database.
This is the code we use to set up our database:
...ANSWER
Answered 2021-Aug-06 at 15:52For posterity, the issue was that we had a reference to the database in our state management library (Zustand) that was being held onto past logout. When we tried to login again, our getOrCreateDatabase
function didn't make a new one but it wasn't valid since we had run database.remove()
in rxdb. We ended up just clearing the Zustand db and calling database.remove()
at one place.
QUESTION
I just changed my rxdb schema version from 0 to 1 in order to add a deletedAt
attribute. I added a migration strategy for going from ver 0 to 1.
Now I'm getting this error: "migration of document failed final document does not match final schema". The final doc is in screenshot below:
I thought maybe I had to add the _rev
field; adding _rev
to schema didn't remove the error, so I've taken it back out. Ditto with a deleted
field (complains I can't add it as a top-level attribute). So I am at a loss as to why else the final object differs from the expected schema?
ANSWER
Answered 2020-Aug-26 at 23:45The problem was that deletedAt
, which I had just added, was defined like this in the json schema:
QUESTION
I'm planning on using rxdb + hasura/postgresql in the backend. I'm reading this rxdb page for example, which off the bat requires sync-able entities to have a deleted
flag.
- Is there ANY point at which I can finally hard-delete these entities? What conditions would have to be met - eg could I simply use "older than X months" and then force my app to only ever displays data for less than X months?
- Is such a hard-delete, if possible, best carried out directly in the central db, since it will be the source of truth? Would there be any repercussions client-side that I'm not foreseeing/understanding?
I foresee the number of deleted
's growing rapidly in my app and i don't want to have to store all this extra data forever.
Q2 (bonus / just curious)
- What is the (algorithmic) basis for needing a 'deleted' flag? Is it that it's just faster to check a flag rather than to check for the omission of an object from, say, a very large list. I apologize if it's kind of a stupid question :(
ANSWER
Answered 2020-Aug-26 at 13:02Ultimately it comes down to a decision that's informed by your particular business/product with regards to how long you want to keep deleted entities in your system. For some applications it's important to always keep a history of deleted things or even individual revisions to records stored as a kind of ledger or history. You'll have to make a judgement call as to how long you want to keep your deleted entities.
I'd recommend that you also add a deleted_at
column if you haven't already and then you could easily leverage something like Hasura's new Scheduled Triggers functionality to run a recurring job that fully deletes records older than whatever your threshold is.
You could also leverage Hasura's permissions system to ensure that rows that have been deleted aren't returned to the client. There is documentation and examples for ways to work with soft deletes and Hasura
For your second question it is definitely much faster to check for the deleted flag on records than to have to try and diff the entire dataset looking for things that are now missing.
QUESTION
I'm developing an app with Electron, but I have a problem to exchange a variable between several files.
In my main.js, I create an RxDB database that is used for my entire project. At this level, I also create handlers allowing the communication between the main process and the render process via IPC. These handlers call various Classes that perform various processes including database insertions, modifications, etc.
In my opinion, I haven't found an efficient way to transmit my variable containing my database to my classes.
Ideally, I should be able to call this database variable (declared in main.js
) at any time from any class. I can't use the IPC system because my returned variable must not be a JSON but absolutely an RxDatabase object.
Here is a very simplified diagram of my main process:
Currently, to share my database variable to my classes:
- I declare the variable in
main.js
- I transmit the variable in the handlers
- I transmit the variable to my classes in a static variable class
Although ugly, this system works. But I think there is a more correct way to do it. Also, it becomes difficult to preserve this variable when a class calls one or more instances of external classes.
Thanks.
...ANSWER
Answered 2020-Aug-18 at 11:42A simple export / import is enough.
Previously, I tried to export my variable from main.js but when I tried to use export {database}
, I had an Unexpeted token export error
.So I had assumed that it would be impossible for me to export a variable from main.js for some obscure reasons specific to Electron.
In fact, you just need to use a ES5 syntax, that way exports.database = database
in main.js.
Then, you can import this variable in any file of your main process.
Thanks @Luke for his answer.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install rxdb
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page