Electron, Databases,
and RxDB
An overview of Electron data storage options,
and a new observable object store.
@bengotow
I want to build Evernote with Electron.

How should I store user’s data?
“Notes”
Recent Notes
Full-text Search Edit Note
• 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?
• 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”]
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!
• 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)
🤔
• 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
SQLite + ORM
SQLite + ORM
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.
• 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.”
Electron-RxDB
• Observable object store built on SQLite:
CoreData for Electron
• Built to power the Nylas N1 mail client,
tuned for performance
Define a Note
Save a Note
Query for Notes
Create a Notes view
Create a Notes view
• 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
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.
Built for Electron
• Multi-window support
• Always builds SQLite for Electron
• Example Electron app: “Notes”
Thanks!
bengotow/electron-RxDB
@bengotow

Electron, databases, and RxDB

  • 1.
    Electron, Databases, and RxDB Anoverview of Electron data storage options, and a new observable object store. @bengotow
  • 2.
    I want tobuild Evernote with Electron.
 How should I store user’s data?
  • 3.
  • 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.
    • Chrome hasgreat 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.
    LocalStorage • Synchronous • Stringsonly • 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.
    • But… Ineed 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.
    • De-facto standardfor relational storage in client- side applications (macOS, iOS, Android, etc.) • Builds everywhere, no dependencies • Simple, fast, reliable • Open source, great documentation
  • 9.
  • 10.
  • 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.
    • 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.
    Electron-RxDB • Observable objectstore built on SQLite: CoreData for Electron • Built to power the Nylas N1 mail client, tuned for performance
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
    • Database isan 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.
    Nylas N1 • RxDBprovides 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.
    Built for Electron •Multi-window support • Always builds SQLite for Electron • Example Electron app: “Notes”
  • 21.