All notable changes to this project will be documented in this file.
Contributors: Please add your changes to CHANGELOG-Unreleased.md
This release has unintentionally broken RxJS for some apps using with-observables
. If you have this issue, please update @nozbe/with-observables
to the latest version.
- [Sync] Conflict resolution can now be customized. See docs for more details
- [Android] Autolinking is now supported
- [LokiJS] Adapter autosave option is now configurable
- Interal RxJS imports have been refactor such that rxjs-compat should never be used now
- [Performance] Tweak Babel config to produce smaller code
- [Performance] LokiJS-based apps will now take up to 30% less time to load the database (id and unique indicies are generated lazily)
- [iOS] Fixed crash on database reset in apps linked against iOS 14 SDK
- [LokiJS] Fix
Q.like
being broken for multi-line strings on web - Fixed warn "import cycle" from DialogProvider (#786) by @gmonte.
- Fixed cache date as instance of Date (#828) by @djorkaeffalexandre.
- [iOS] Added CocoaPods support - @leninlin
- [NodeJS] Introducing a new SQLite Adapter based integration to NodeJS. This requires a peer dependency on better-sqlite3 and should work with the same configuration as iOS/Android - @sidferreira
- [Android]
exerimentalUseJSI
option has been enabled on Android. However, it requires some app-specific setup which is not yet documented - stay tuned for upcoming releases - [Schema] [Migrations] You can now pass
unsafeSql
parameters to schema builder and migration steps to modify SQL generated to set up the database or perform migrations. There's also newunsafeExecuteSql
migration step. Please use this only if you know what you're doing — you shouldn't need this in 99% of cases. See Schema and Migrations docs for more details - [LokiJS] [Performance] Added experimental
onIndexedDBFetchStart
andindexedDBSerializer
options toLokiJSAdapter
. These can be used to improve app launch time. Seesrc/adapters/lokijs/index.js
for more details.
- [Performance] findAndObserve is now able to emit a value synchronously. By extension, this makes Relations put into withObservables able to render the child component in one shot. Avoiding the extra unnecessary render cycles avoids a lot of DOM and React commit-phase work, which can speed up loading some views by 30%
- [Performance] LokiJS is now faster (refactored encodeQuery, skipped unnecessary clone operations)
Another WatermelonDB release after just a week? Yup! And it's jam-packed full of features!
-
[Query]
Q.on
queries are now far more flexible. Previously, they could only be placed at the top level of a query. See Docs for more details. Now, you can:-
Pass multiple conditions on the related query, like so:
collection.query( Q.on('projects', [ Q.where('foo', 'bar'), Q.where('bar', 'baz'), ]) )
-
You can place
Q.on
deeper inside the query (nested insideQ.and()
,Q.or()
). However, you must explicitly list all tables you're joining on at the beginning of a query, using:Q.experimentalJoinTables(['join_table1', 'join_table2'])
. -
You can nest
Q.on
conditions insideQ.on
, e.g. to make a condition on a grandchild. To do so, it's required to passQ.experimentalNestedJoin('parent_table', 'grandparent_table')
at the beginning of a query
-
-
[Query]
Q.unsafeSqlExpr()
andQ.unsafeLokiExpr()
are introduced to allow adding bits of queries that are not supported by the WatermelonDB query language without having to useunsafeFetchRecordsWithSQL()
. See docs for more details -
[Query]
Q.unsafeLokiFilter((rawRecord, loki) => boolean)
can now be used as an escape hatch to make queries with LokiJSAdapter that are not otherwise possible (e.g. multi-table column comparisons). See docs for more details
- [Performance] [LokiJS] Improved performance of queries containing query comparisons on LokiJSAdapter
- [Docs] Added Contributing guide for Query language improvements
- [Deprecation]
Query.hasJoins
is deprecated - [DX] Queries with bad associations now show more helpful error message
- [Query] Counting queries that contain
Q.experimentalTake
/Q.experimentalSkip
is currently broken - previously it would return incorrect results, but now it will throw an error to avoid confusion. Please contribute to fix the root cause!
- [Typescript] Fixed types of Relation
QueryDescription
structure has been changed.
- Fixed broken iOS build - @mlecoq
-
[Sync] Introducing Migration Syncs - this allows fully consistent synchronization when migrating between schema versions. Previously, there was no mechanism to incrementally fetch all remote changes in new tables and columns after a migration - so local copy was likely inconsistent, requiring a re-login. After adopting migration syncs, Watermelon Sync will request from backend all missing information. See Sync docs for more details.
-
[iOS] Introducing a new native SQLite database integration, rewritten from scratch in C++, based on React Native's JSI (JavaScript Interface). It is to be considered experimental, however we intend to make it the default (and eventually, the only) implementation. In a later release, Android version will be introduced.
The new adapter is up to 3x faster than the previously fastest `synchronous: true` option, however this speedup is only achieved with some unpublished React Native patches. To try out JSI, add `experimentalUseJSI: true` to `SQLiteAdapter` constructor.
-
[Query] Added
Q.experimentalSortBy(sortColumn, sortOrder)
,Q.experimentalTake(count)
,Q.experimentalSkip(count)
methods (only availble with SQLiteAdapter) - @Kenneth-KT -
Database.batch()
can now be called with a single array of models -
[DX]
Database.get(tableName)
is now a shortcut forDatabase.collections.get(tableName)
-
[DX] Query is now thenable - you can now use
await query
andawait query.count
instead ofawait query.fetch()
andawait query.fetchCount()
-
[DX] Relation is now thenable - you can now use
await relation
instead ofawait relation.fetch()
-
[DX] Exposed
collection.db
andmodel.db
as shortcuts to get to their Database object
- [Hardening] Column and table names starting with
__
, Object property names (e.g.constructor
), and some reserved keywords are now forbidden - [DX] [Hardening] QueryDescription builder methods do tighter type checks, catching more bugs, and preventing users from unwisely passing unsanitized user data into Query builder methods
- [DX] [Hardening] Adapters check early if table names are valid
- [DX] Collection.find reports an error more quickly if an obviously invalid ID is passed
- [DX] Intializing Database with invalid model classes will now show a helpful error
- [DX] DatabaseProvider shows a more helpful error if used improperly
- [Sync] Sync no longer fails if pullChanges returns collections that don't exist on the frontend - shows a warning instead. This is to make building backwards-compatible backends less error-prone
- [Sync] [Docs] Sync documentation has been rewritten, and is now closer in detail to a formal specification
- [Hardening] database.collections.get() better validates passed value
- [Hardening] Prevents unsafe strings from being passed as column name/table name arguments in QueryDescription
- [Sync] Fixed
RangeError: Maximum call stack size exceeded
when syncing large amounts of data - @leninlin - [iOS] Fixed a bug that could cause a database operation to fail with an (6) SQLITE_LOCKED error
- [iOS] Fixed 'jsi/jsi.h' file not found when building at the consumer level. Added path
$(SRCROOT)/../../../../../ios/Pods/Headers/Public/React-jsi
to Header Search Paths (issue #691) - @victorbutler - [Native] SQLite keywords used as table or column names no longer crash
- Fixed potential issues when subscribing to database, collection, model, queries passing a subscriber function with the same identity more than once
- Fixed broken adapter tests
This is a security patch for a vulnerability that could cause maliciously crafted record IDs to cause all or some of user's data to be deleted. More information available via GitHub security advisory
Database.unsafeResetDatabase()
is now less unsafe — more application bugs are being caught
- [iOS] Fix build in apps using Flipper
- [Typescript] Added type definition for
setGenerator
. - [Typescript] Fixed types of decorators.
- [Typescript] Add Tests to test Types.
- Fixed typo in learn-to-use docs.
- [Typescript] Fixed types of changes.
- [SQLite] Infrastruture for a future JSI adapter has been added
experimentalUseIncrementalIndexedDB
has been renamed touseIncrementalIndexedDB
- [adapters] Adapter API has changed from returning Promise to taking callbacks as the last argument. This won't affect you unless you call on adapter methods directly.
database.adapter
returns a newDatabaseAdapterCompat
which has the same shape as old adapter API. You can usedatabase.adapter.underlyingAdapter
to get backSQLiteAdapter
/LokiJSAdapter
- [Collection]
Collection.fetchQuery
andCollection.fetchCount
are removed. Please useQuery.fetch()
andQuery.fetchCount()
.
- [SQLiteAdapter] [iOS] Add new
synchronous
option to adapter:new SQLiteAdapter({ ..., synchronous: true })
. When enabled, database operations will block JavaScript thread. Adapter actions will resolve in the next microtask, which simplifies building flicker-free interfaces. Adapter will fall back to async operation when synchronous adapter is not available (e.g. when doing remote debugging) - [LokiJS] Added new
onQuotaExceededError?: (error: Error) => void
option toLokiJSAdapter
constructor. This is called when underlying IndexedDB encountered a quota exceeded error (ran out of allotted disk space for app) This means that app can't save more data or that it will fall back to using in-memory database only Note that this only works whenuseWebWorker: false
- [Performance] Watermelon internals have been rewritten not to rely on Promises and allow some fetch/observe calls to resolve synchronously. Do not rely on this -- external API is still based on Rx and Promises and may resolve either asynchronously or synchronously depending on capabilities. This is meant as a internal performance optimization only for the time being.
- [LokiJS] [Performance] Improved worker queue implementation for performance
- [observation] Refactored observer implementations for performance
- Fixed a possible cause for "Record ID xxx#yyy was sent over the bridge, but it's not cached" error
- [LokiJS] Fixed an issue preventing database from saving when using
experimentalUseIncrementalIndexedDB
- Fixed a potential issue when using
database.unsafeResetDatabase()
- [iOS] Fixed issue with clearing database under experimental synchronous mode
- [Model] Added experimental
model.experimentalSubscribe((isDeleted) => { ... })
method as a vanilla JS alternative to Rx basedmodel.observe()
. Unlike the latter, it does not notify the subscriber immediately upon subscription. - [Collection] Added internal
collection.experimentalSubscribe((changeSet) => { ... })
method as a vanilla JS alternative to Rx basedcollection.changes
(you probably shouldn't be using this API anyway) - [Database] Added experimental
database.experimentalSubscribe(['table1', 'table2'], () => { ... })
method as a vanilla JS alternative to Rx-baseddatabase.withChangesForTables()
. Unlike the latter,experimentalSubscribe
notifies the subscriber only once after a batch that makes a change in multiple collections subscribed to. It also doesn't notify the subscriber immediately upon subscription, and doesn't send details about the changes, only a signal. - Added
experimentalDisableObserveCountThrottling()
to@nozbe/watermelondb/observation/observeCount
that globally disables count observation throttling. We think that throttling on WatermelonDB level is not a good feature and will be removed in a future release - and will be better implemented on app level if necessary - [Query] Added experimental
query.experimentalSubscribe(records => { ... })
,query.experimentalSubscribeWithColumns(['col1', 'col2'], records => { ... })
, andquery.experimentalSubscribeToCount(count => { ... })
methods
This is a massive new update to WatermelonDB! 🍉
-
Up to 23x faster sync. You heard that right. We've made big improvements to performance. In our tests, with a massive sync (first login, 45MB of data / 65K records) we got a speed up of:
- 5.7s -> 1.2s on web (5x)
- 142s -> 6s on iOS (23x)
Expect more improvements in the coming releases!
-
Improved LokiJS adapter. Option to disable web workers, important Safari 13 fix, better performance, and now works in Private Modes. We recommend adding
useWebWorker: false, experimentalUseIncrementalIndexedDB: true
options to theLokiJSAdapter
constructor to take advantage of the improvements, but please read further changelog to understand the implications of this. -
Raw SQL queries now available on iOS and Android thanks to the community
-
Improved TypeScript support — thanks to the community
- Deprecated
bool
schema column type is removed -- please change toboolean
- Experimental
experimentalSetOnlyMarkAsChangedIfDiffers(false)
API is now removed
-
[Collection] Add
Collection.unsafeFetchRecordsWithSQL()
method. You can use it to fetch record using raw SQL queries on iOS and Android. Please be careful to avoid SQL injection and other pitfalls of raw queries -
[LokiJS] Introduces new
new LokiJSAdapter({ ..., experimentalUseIncrementalIndexedDB: true })
option. When enabled, database will be saved to browser's IndexedDB using a new adapter that only saves the changed records, instead of the entire database.This works around a serious bug in Safari 13 (https://bugs.webkit.org/show_bug.cgi?id=202137) that causes large databases to quickly balloon to gigabytes of temporary trash
This also improves performance of incremental saves, although initial page load or very, very large saves might be slightly slower.
This is intended to become the new default option, but it's not backwards compatible (if enabled, old database will be lost). You're welcome to contribute an automatic migration code.
Note that this option is still experimental, and might change in breaking ways at any time.
-
[LokiJS] Introduces new
new LokiJSAdapter({ ..., useWebWorker: false })
option. Before, web workers were always used withLokiJSAdapter
. Although web workers may have some performance benefits, disabling them may lead to lower memory consumption, lower latency, and easier debugging. YMMV. -
[LokiJS] Added
onIndexedDBVersionChange
option toLokiJSAdapter
. This is a callback that's called when internal IDB version changed (most likely the database was deleted in another browser tab). Pass a callback to force log out in this copy of the app as well. Note that this only works when using incrementalIDB and not using web workers -
[Model] Add
Model._dangerouslySetRawWithoutMarkingColumnChange()
method. You probably shouldn't use it, but if you know what you're doing and want to live-update records from server without marking record as updated, this is useful -
[Collection] Add
Collection.prepareCreateFromDirtyRaw()
-
@json decorator sanitizer functions take an optional second argument, with a reference to the model
- Pinned required
rambdax
version to 2.15.0 to avoid console logging bug. In a future release we will switch to our own fork oframbdax
to avoid future breakages like this.
- [Performance] Make large batches a lot faster (1.3s shaved off on a 65K insert sample)
- [Performance] [iOS] Make large batch inserts an order of magnitude faster
- [Performance] [iOS] Make encoding very large queries (with thousands of parameters) 20x faster
- [Performance] [LokiJS] Make batch inserts faster (1.5s shaved off on a 65K insert sample)
- [Performance] [LokiJS] Various performance improvements
- [Performance] [Sync] Make Sync faster
- [Performance] Make observation faster
- [Performance] [Android] Make batches faster
- Fix app glitches and performance issues caused by race conditions in
Query.observeWithColumns()
- [LokiJS] Persistence adapter will now be automatically selected based on availability. By default, IndexedDB is used. But now, if unavailable (e.g. in private mode), ephemeral memory adapter will be used.
- Disabled console logs regarding new observations (it never actually counted all observations) and time to query/count/batch (the measures were wildly inaccurate because of asynchronicity - actual times are much lower)
- [withObservables] Improved performance and debuggability (update withObservables package separately)
- Improved debuggability of Watermelon -- shortened Rx stacks and added function names to aid in understanding call stacks and profiles
- [adapters] The adapters interface has changed.
query()
andcount()
methods now receive aSerializedQuery
, andbatch()
now takesTableName<any>
andRawRecord
orRecordId
instead ofModel
. - [Typescript] Typing improvements
- Added 3 missing properties
collections
,database
andasModel
in Model type definition. - Removed optional flag on
actionsEnabled
in the Database constructor options since its mandatory since 0.13.0. - fixed several further typing issues in Model, Relation and lazy decorator
- Added 3 missing properties
- Changed how async functions are transpiled in the library. This could break on really old Android phones but shouldn't matter if you use latest version of React Native. Please report an issue if you see a problem.
- Avoid
database
prop drilling in the web demo
Hotfix for rambdax crash
- [Schema] Handle invalid table schema argument in appSchema
- [withObservables] Added TypeScript support (changelog)
- [Electron] avoid
Uncaught ReferenceError: global is not defined
in electron runtime (#453) - [rambdax] Replaces
contains
withincludes
due tocontains
deprecation https://github.com/selfrefactor/rambda/commit/1dc1368f81e9f398664c9d95c2efbc48b5cdff9b#diff-04c6e90faac2675aa89e2176d2eec7d8R2209
- [Query] Added support for
notLike
queries 🎉 - [Actions] You can now batch delete record with all descendants using experimental functions
experimentalMarkAsDeleted
orexperimentalDestroyPermanently
-
[Database] It is now mandatory to pass
actionsEnabled:
option to Database constructor. It is recommended that you enable this option:const database = new Database({ adapter: ..., modelClasses: [...], actionsEnabled: true })
See
docs/Actions.md
for more details about Actions. You can also passfalse
to maintain backward compatibility, but this option will be removed in a later version -
[Adapters]
migrationsExperimental
prop ofSQLiteAdapter
andLokiJSAdapter
has been renamed tomigrations
.
- [Actions] You can now batch deletes by using
prepareMarkAsDeleted
orprepareDestroyPermanently
- [Sync] Performance:
synchronize()
no longer calls yourpushChanges()
function if there are no local changes to push. This is meant to save unnecessary network bandwidth.⚠️ Note that this could be a breaking change if you rely on it always being called - [Sync] When setting new values to fields on a record, the field (and record) will no longer be
marked as changed if the field's value is the same. This is meant to improve performance and avoid
unnecessary code in the app.
⚠️ Note that this could be a breaking change if you rely on the old behavior. For now you can importexperimentalSetOnlyMarkAsChangedIfDiffers
from@nozbe/watermelondb/Model/index
and call if with(false)
to bring the old behavior back, but this will be removed in the later version -- create a new issue explaining why you need this - [Sync] Small perf improvements
- [Typescript] Improved types for SQLite and LokiJS adapters, migrations, models, the database and the logger.
- [Database] You can now update the random id schema by importing
import { setGenerator } from '@nozbe/watermelondb/utils/common/randomId'
and then callingsetGenerator(newGenenerator)
. This allows WatermelonDB to create specific IDs for example if your backend uses UUIDs. - [Typescript] Type improvements to SQLiteAdapter and Database
- [Tests] remove cleanup for [email protected] compatibility
- [TypeScript] 'Cannot use 'in' operator to search for 'initializer'; decorator fix
- [Database] You can now pass falsy values to
Database.batch(...)
(false, null, undefined). This is useful in keeping code clean when doing operations conditionally. (Also works withmodel.batch(...)
) - [Decorators]. You can now use
@action
on methods of any object that has adatabase: Database
property, and@field @children @date @relation @immutableRelation @json @text @nochange
decorators on any object with aasModel: Model
property. - [Sync] Adds a temporary/experimental
_unsafeBatchPerCollection: true
flag tosynchronize()
. This causes server changes to be committed to database in multiple batches, and not one. This is NOT preferred for reliability and performance reasons, but it works around a memory issue that might cause your app to crash on very large syncs (>20,000 records). Use this only if necessary. Note that this option might be removed at any time if a better solution is found.
-
[iOS] Fix runtime crash when built with Xcode 10.2 (Swift 5 runtime).
⚠️ Note: You need to upgrade to React Native 0.59.3 for this to work. If you can't upgrade React Native yet, either stick to Xcode 10.1 or manually apply this patch: https://github.com/Nozbe/WatermelonDB/pull/302/commits/aa4e08ad0fa55f434da2a94407c51fc5ff18e506
- [Sync] Adds basic sync logging capability to Sync. Pass an empty object to
synchronize()
to populate it with diagnostic information:See Sync documentation for more details.const log = {} await synchronize({ database, log, ...}) console.log(log.startedAt)
- [Hooks] new
useDatabase
hook for consuming the Database Context:import { useDatabase } from '@nozbe/watermelondb/hooks'; const Component = () => { const database = useDatabase(); }
- [TypeScript] added
.d.ts
files. Please note: TypeScript definitions are currently incomplete and should be used as a guide only. PRs for improvements would be greatly appreciated!
- Improved UI performance by consolidating multiple observation emissions into a single per-collection batch emission when doing batch changes
⚠️ Potentially BREAKING fix: a@date
field now returns a Jan 1, 1970 date instead ofnull
if the field's raw value is0
. This is considered a bug fix, since it's unexpected to receive anull
from a getter of a field whose column schema doesn't sayisOptional: true
. However, if you relied on this behavior, this might be a breaking change.⚠️ BREAKING:Database.unsafeResetDatabase()
now requires that you run it inside an Action
- [Sync] Fixed an issue where synchronization would continue running despite
unsafeResetDatabase
being called - [Android] fix compile error for kotlin 1.3+
- Actions are now aborted when
unsafeResetDatabase()
is called, making reseting database a little bit safer - Updated demo dependencies
- LokiJS is now a dependency of WatermelonDB (although it's only required for use on the web)
- [Android] removed unused test class
- [Android] updated ktlint to
0.30.0
- [Android] Changed
compile
toimplementation
in Library Gradle file⚠️ might break build if you are using Android Gradle Plugin <3.X
- Updated
peerDependency
react-native
to0.57.0
- [Sync] Added
hasUnsyncedChanges()
helper method - [Sync] Improved documentation for backends that can't distinguish between
created
andupdated
records - [Sync] Improved diagnostics / protection against edge cases
- [iOS] Add missing
header search path
to support ejected expo project. - [Android] Fix crash on android < 5.0
- [iOS]
SQLiteAdapter
'sdbName
path now allows you to pass an absolute path to a file, instead of a name - [Web] Add adaptive layout for demo example with smooth scrolling for iOS
- BREAKING: Table column
last_modified
is no longer automatically added to all database tables. If you don't use this column (e.g. in your custom sync code), you don't have to do anything. If you do, manually add this column to all table definitions in your Schema:Don't bump schema version or write a migration for this.{ name: 'last_modified', type: 'number', isOptional: true }
-
Actions API.
This was actually released in 0.8.0 but is now documented in CRUD.md and Actions.md. With Actions enabled, all create/update/delete/batch calls must be wrapped in an Action.
To use Actions, call
await database.action(async () => { /* perform writes here */ }
, and in Model instance methods, you can just decorate the whole method with@action
.This is necessary for Watermelon Sync, and also to enable greater safety and consistency.
To enable actions, add
actionsEnabled: true
tonew Database({ ... })
. In a future release this will be enabled by default, and later, made mandatory.See documentation for more details.
-
Watermelon Sync Adapter (Experimental)
Added
synchronize()
function that allows you to easily add full synchronization capabilities to your Watermelon app. You only need to provide two fetch calls to your remote server that conforms to Watermelon synchronization protocol, and all the client-side processing (applying remote changes, resolving conflicts, finding local changes, and marking them as synced) is done by Watermelon.See documentation for more details.
-
Support caching for non-global IDs at Native level
- Added
Q.like
- you can now make queries similar to SQLLIKE
- Added
DatabaseProvider
andwithDatabase
Higher-Order Component to reduce prop drilling - Added experimental Actions API. This will be documented in a future release.
- Fixes crash on older Android React Native targets without
jsc-android
installed
- [Schema] Column type 'bool' is deprecated — change to 'boolean'
- Added support for Schema Migrations. See documentation for more details.
- Added fundaments for integration of Danger with Jest
- Fixed "dependency cycle" warning
- [SQLite] Fixed rare cases where database could be left in an unusable state (added missing transaction)
- [Flow] Fixes
oneOf()
typing and some other variance errors - [React Native] App should launch a little faster, because schema is only compiled on demand now
- Fixed typos in README.md
- Updated Flow to 0.85
- The
@nozbe/watermelondb/babel/cjs
/@nozbe/watermelondb/babel/esm
Babel plugin that ships with Watermelon is deprecated and no longer necessary. Delete it from your Babel config as it will be removed in a future update
- Removed dependency on
async
(Web Worker should be ~30KB smaller) - Refactored
Collection
andsimpleObserver
for getting changes in an array and also adds CollectionChangeTypes for differentiation between different changes - Updated dependencies
- Simplified build system by using relative imports
- Simplified build package by outputting CJS-only files
- Added iOS and Android integration tests and lint checks to TravisCI
- Changed Flow setup for apps using Watermelon - see docs/Advanced/Flow.md
- Improved documentation, and demo code
- Updated dependencies
- Add quotes to all names in sql queries to allow keywords as table or column names
- Fixed running model tests in apps with Watermelon in the loop
- Fixed Flow when using Watermelon in apps
Initial release of WatermelonDB