Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Electron, databases, and RxDB


Published on

An overview of Electron data storage options (IndexedDB, LocalStorage, SQLite), and a new observable object store.

Published in: Engineering
  • Dating direct: ❶❶❶ ❶❶❶
    Are you sure you want to  Yes  No
    Your message goes here
  • Sex in your area is here: ♥♥♥ ♥♥♥
    Are you sure you want to  Yes  No
    Your message goes here

Electron, databases, and RxDB

  1. 1. Electron, Databases, and RxDB An overview of Electron data storage options, and a new observable object store. @bengotow
  2. 2. I want to build Evernote with Electron.
 How should I store user’s data?
  3. 3. “Notes” Recent Notes Full-text Search Edit Note
  4. 4. • One user, their persistent filesystem • For small datasets (<1,000 items), loading / saving JSON and filtering it in memory is fine. Do I need a database?
  5. 5. • Chrome has great key-value storage options, and we can manually maintain indexes. Do I need a relational database? KEY VALUE A {“name”:”My first document.. B {“name”:”Another note… C {“name”: “Favorite note… RECENT_IDS [“B”, “C”]
  6. 6. LocalStorage • Synchronous • Strings only • Retrieve keys • <10MB (#8337) Key Value Storage IndexedDB • Sync or async • Strings, JSON • Retrieve keys, ranges • Indexed scan for key • < 1/3 free disk space Or use the Filesystem!
  7. 7. • But… I need full-text search • But… I want to query and sort by arbitrary fields • But… I want to support millions of notes • But… I may need more than 1/3 of the available disk space. (IndexedDB limit) 🤔
  8. 8. • De-facto standard for relational storage in client- side applications (macOS, iOS, Android, etc.) • Builds everywhere, no dependencies • Simple, fast, reliable • Open source, great documentation
  9. 9. SQLite + ORM
  10. 10. SQLite + ORM
  11. 11. But… for Electron? • Most JavaScript database wrappers were built for server-side NodeJS. • Heavy focus on querying, connection pools, etc., limited APIs for connecting models to views.
  12. 12. • CoreData (iOS): NSFetchedResultsController • YapDatabase (iOS): YapDatabaseView • AndroidSQLite (Android): View “Cursors” “Give me the notes matching this query, and let me know if the results change.”
  13. 13. Electron-RxDB • Observable object store built on SQLite: CoreData for Electron • Built to power the Nylas N1 mail client, tuned for performance
  14. 14. Define a Note
  15. 15. Save a Note Query for Notes
  16. 16. Create a Notes view
  17. 17. Create a Notes view
  18. 18. • Database is an EventEmitter, broadcasts events when transactions are committed. • Queries return RxJS Observables that emit new result sets as transactions are committed.
 • Optimizations prevent RxDB from re-running SQL queries in common cases SQLite 💖 RxJS
  19. 19. Nylas N1 • RxDB provides live “slices” of 1GB+ of mail data • Views bind to Flux / Redux stores for application state, RxDB queries for data. • Many features (mail rules, notifications, etc.) implemented with database listeners.
  20. 20. Built for Electron • Multi-window support • Always builds SQLite for Electron • Example Electron app: “Notes”
  21. 21. Thanks! bengotow/electron-RxDB @bengotow