Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
radex committed Nov 8, 2019
1 parent 2ba198a commit a838682
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 23 deletions.
1 change: 1 addition & 0 deletions docs/Advanced/AdvancedFields.html
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ <h2><a class="header" href="#json" id="json"><code>@json</code></a></h2>
<p>If you don't want to sanitize JSON, pass an identity function:</p>
<pre><code class="language-js">const sanitizeReactions = json =&gt; json
</code></pre>
<p>The sanitizer function takes an optional second argument, which is a reference to the model. This is useful is your sanitization logic depends on the other fields in the model.</p>
<p><strong>Warning about JSON fields</strong>:</p>
<p>JSON fields go against relational, lazy nature of Watermelon, because <strong>you can't query or count by the contents of JSON fields</strong>. If you need or might need in the future to query records by some piece of data, don't use JSON.</p>
<p>Only use JSON fields when you need the flexibility of complex freeform data, or the speed of having metadata without querying another table, and you are sure that you won't need to query by those metadata.</p>
Expand Down
6 changes: 6 additions & 0 deletions docs/Advanced/Sync.html
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ <h3><a class="header" href="#implementation-tips" id="implementation-tips">Imple
</ul>
</li>
</ul>
<h3><a class="header" href="#existing-backend-implementations-for-watermelondb" id="existing-backend-implementations-for-watermelondb">Existing backend implementations for WatermelonDB</a></h3>
<p>Note that those are not maintained by WatermelonDB, and we make no endorsements about quality of these projects:</p>
<ul>
<li>https://github.com/AliAllaf/firemelon</li>
<li>Did you make one? Please contribute a link!</li>
</ul>
<h3><a class="header" href="#current-limitations" id="current-limitations">Current limitations</a></h3>
<ol>
<li>If a record being pushed changes between pull and push, push will just fail. It would be better if it failed with a list of conflicts, so that <code>synchronize()</code> can automatically respond. Alternatively, sync could only send changed fields and server could automatically always just apply those changed fields to the server version (since that's what per-column client-wins resolver will do anyway)</li>
Expand Down
114 changes: 110 additions & 4 deletions docs/CHANGELOG.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,112 @@ <h1 class="menu-title">WatermelonDB documentation</h1>
<h1><a class="header" href="#changelog" id="changelog">Changelog</a></h1>
<p>All notable changes to this project will be documented in this file.</p>
<h2><a class="header" href="#unreleased" id="unreleased">Unreleased</a></h2>
<h2><a class="header" href="#015---2019-11-08" id="015---2019-11-08">0.15 - 2019-11-08</a></h2>
<h3><a class="header" href="#highlights" id="highlights">Highlights</a></h3>
<p>This is a <strong>massive</strong> new update to WatermelonDB! 🍉</p>
<ul>
<li>
<p><strong>Up to 23x faster sync</strong>. 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:</p>
<ul>
<li>5.7s -&gt; 1.2s on web (5x)</li>
<li>142s -&gt; 6s on iOS (23x)</li>
</ul>
<p>Expect more improvements in the coming releases!</p>
</li>
<li>
<p><strong>Improved LokiJS adapter</strong>. Option to disable web workers, important Safari 13 fix, better performance,
and now works in Private Modes. We recommend adding <code>useWebWorker: false, experimentalUseIncrementalIndexedDB: true</code> options to the <code>LokiJSAdapter</code> constructor to take advantage of the improvements, but please read further changelog to understand the implications of this.</p>
</li>
<li>
<p><strong>Raw SQL queries</strong> now available on iOS and Android thanks to the community</p>
</li>
<li>
<p><strong>Improved TypeScript support</strong> — thanks to the community</p>
</li>
</ul>
<h3><a class="header" href="#-breaking" id="-breaking">⚠️ Breaking</a></h3>
<ul>
<li>Deprecated <code>bool</code> schema column type is removed -- please change to <code>boolean</code></li>
<li>Experimental <code>experimentalSetOnlyMarkAsChangedIfDiffers(false)</code> API is now removed</li>
</ul>
<h3><a class="header" href="#new-featuers" id="new-featuers">New featuers</a></h3>
<ul>
<li>
<p>[Collection] Add <code>Collection.unsafeFetchRecordsWithSQL()</code> 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</p>
</li>
<li>
<p>[LokiJS] Introduces new <code>new LokiJSAdapter({ ..., experimentalUseIncrementalIndexedDB: true })</code> 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.</p>
<p><strong>This works around a serious bug in Safari 13</strong> (https://bugs.webkit.org/show_bug.cgi?id=202137) that causes large
databases to quickly balloon to gigabytes of temporary trash</p>
<p>This also improves performance of incremental saves, although initial page load or very, very large saves
might be slightly slower.</p>
<p>This is intended to become the new default option, but it's not backwards compatible (if enabled, old database
will be lost). <strong>You're welcome to contribute an automatic migration code.</strong></p>
<p>Note that this option is still experimental, and might change in breaking ways at any time.</p>
</li>
<li>
<p>[LokiJS] Introduces new <code>new LokiJSAdapter({ ..., useWebWorker: false })</code> option. Before, web workers
were always used with <code>LokiJSAdapter</code>. Although web workers may have some performance benefits, disabling them
may lead to lower memory consumption, lower latency, and easier debugging. YMMV.</p>
</li>
<li>
<p>[LokiJS] Added <code>onIndexedDBVersionChange</code> option to <code>LokiJSAdapter</code>. 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</p>
</li>
<li>
<p>[Model] Add <code>Model._dangerouslySetRawWithoutMarkingColumnChange()</code> 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</p>
</li>
<li>
<p>[Collection] Add <code>Collection.prepareCreateFromDirtyRaw()</code></p>
</li>
<li>
<p>@json decorator sanitizer functions take an optional second argument, with a reference to the model</p>
</li>
</ul>
<h3><a class="header" href="#fixes" id="fixes">Fixes</a></h3>
<ul>
<li>Pinned required <code>rambdax</code> version to 2.15.0 to avoid console logging bug. In a future release we will switch to our own fork of <code>rambdax</code> to avoid future breakages like this.</li>
</ul>
<h3><a class="header" href="#improvements" id="improvements">Improvements</a></h3>
<ul>
<li>[Performance] Make large batches a lot faster (1.3s shaved off on a 65K insert sample)</li>
<li>[Performance] [iOS] Make large batch inserts an order of magnitude faster</li>
<li>[Performance] [iOS] Make encoding very large queries (with thousands of parameters) 20x faster</li>
<li>[Performance] [LokiJS] Make batch inserts faster (1.5s shaved off on a 65K insert sample)</li>
<li>[Performance] [LokiJS] Various performance improvements</li>
<li>[Performance] [Sync] Make Sync faster</li>
<li>[Performance] Make observation faster</li>
<li>[Performance] [Android] Make batches faster</li>
<li>Fix app glitches and performance issues caused by race conditions in <code>Query.observeWithColumns()</code></li>
<li>[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.</li>
<li>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)</li>
<li>[withObservables] Improved performance and debuggability (update withObservables package separately)</li>
<li>Improved debuggability of Watermelon -- shortened Rx stacks and added function names to aid in understanding
call stacks and profiles</li>
<li>[adapters] The adapters interface has changed. <code>query()</code> and <code>count()</code> methods now receive a <code>SerializedQuery</code>, and <code>batch()</code> now takes <code>TableName&lt;any&gt;</code> and <code>RawRecord</code> or <code>RecordId</code> instead of <code>Model</code>.</li>
<li>[Typescript] Typing improvements
<ul>
<li>Added 3 missing properties <code>collections</code>, <code>database</code> and <code>asModel</code> in Model type definition.</li>
<li>Removed optional flag on <code>actionsEnabled</code> in the Database constructor options since its mandatory since 0.13.0.</li>
<li>fixed several further typing issues in Model, Relation and lazy decorator</li>
</ul>
</li>
<li>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.</li>
<li>Avoid <code>database</code> prop drilling in the web demo</li>
</ul>
<h2><a class="header" href="#0141---2019-08-31" id="0141---2019-08-31">0.14.1 - 2019-08-31</a></h2>
<p>Hotfix for rambdax crash</p>
<ul>
Expand All @@ -163,7 +269,7 @@ <h3><a class="header" href="#new-features" id="new-features">New features</a></h
<li>[Actions] You can now batch delete record with all descendants using experimental functions <code>experimentalMarkAsDeleted</code> or <code>experimentalDestroyPermanently</code></li>
</ul>
<h2><a class="header" href="#0130---2019-07-18" id="0130---2019-07-18">0.13.0 - 2019-07-18</a></h2>
<h3><a class="header" href="#-breaking" id="-breaking">⚠️ Breaking</a></h3>
<h3><a class="header" href="#-breaking-1" id="-breaking-1">⚠️ Breaking</a></h3>
<ul>
<li>
<p>[Database] It is now mandatory to pass <code>actionsEnabled:</code> option to Database constructor.
Expand Down Expand Up @@ -196,7 +302,7 @@ <h3><a class="header" href="#new-features-1" id="new-features-1">New features</a
this will be removed in the later version -- create a new issue explaining why you need this</li>
<li>[Sync] Small perf improvements</li>
</ul>
<h3><a class="header" href="#improvements" id="improvements">Improvements</a></h3>
<h3><a class="header" href="#improvements-1" id="improvements-1">Improvements</a></h3>
<ul>
<li>[Typescript] Improved types for SQLite and LokiJS adapters, migrations, models, the database and the logger.</li>
</ul>
Expand All @@ -210,7 +316,7 @@ <h3><a class="header" href="#changes" id="changes">Changes</a></h3>
<li>[Tests] remove cleanup for [email protected] compatibility</li>
</ul>
<h2><a class="header" href="#0122---2019-04-19" id="0122---2019-04-19">0.12.2 - 2019-04-19</a></h2>
<h3><a class="header" href="#fixes" id="fixes">Fixes</a></h3>
<h3><a class="header" href="#fixes-1" id="fixes-1">Fixes</a></h3>
<ul>
<li>[TypeScript] 'Cannot use 'in' operator to search for 'initializer'; decorator fix</li>
</ul>
Expand Down Expand Up @@ -346,7 +452,7 @@ <h3><a class="header" href="#new-2" id="new-2">New</a></h3>
<li>Added <code>DatabaseProvider</code> and <code>withDatabase</code> Higher-Order Component to reduce prop drilling</li>
<li>Added experimental Actions API. This will be documented in a future release.</li>
</ul>
<h3><a class="header" href="#fixes-1" id="fixes-1">Fixes</a></h3>
<h3><a class="header" href="#fixes-2" id="fixes-2">Fixes</a></h3>
<ul>
<li>Fixes crash on older Android React Native targets without <code>jsc-android</code> installed</li>
</ul>
Expand Down
6 changes: 6 additions & 0 deletions docs/Installation.html
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,12 @@ <h2><a class="header" href="#set-up-database" id="set-up-database">Set up <code>

const adapter = new LokiJSAdapter({
schema,
// useWebWorker: false,
// experimentalUseIncrementalIndexedDB: true,
// onIndexedDBVersionChange: () =&gt; {
// // database was deleted in another browser tab
// services.forceLogOut()
// },
})

// The rest is the same!
Expand Down
9 changes: 6 additions & 3 deletions docs/Query.html
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ <h3><a class="header" href="#conditions-with-other-operators" id="conditions-wit
<tr><td><code>Q.where('status', Q.like('%bl_sh%'))</code></td><td><code>/.*bl.sh.*/i</code> (See note below!)</td></tr>
<tr><td><code>Q.where('status', Q.notLike('%bl_sh%'))</code></td><td><code>/^((!?.*bl.sh.*).)*$/i</code> (Inverse regex match) (See note below!)</td></tr>
</tbody></table>
<p><strong>Note:</strong> It's NOT SAFE to use <code>Q.like</code> and <code>Q.notLike</code> with user input directly, because special characters like <code>%</code> or <code>_</code> are not escaped. Always sanitize user input like so: </p>
<p><strong>Note:</strong> It's NOT SAFE to use <code>Q.like</code> and <code>Q.notLike</code> with user input directly, because special characters like <code>%</code> or <code>_</code> are not escaped. Always sanitize user input like so:</p>
<pre><code class="language-js">Q.like(`%${Q.sanitizeLikeString(userInput)}%`)
Q.notLike(`%${Q.sanitizeLikeString(userInput)}%`)
</code></pre>
Expand Down Expand Up @@ -278,8 +278,11 @@ <h3><a class="header" href="#column-comparisons" id="column-comparisons">Column
Q.where('likes', Q.gt(Q.column('dislikes')))
)
</code></pre>
<h3><a class="header" href="#raw-queries" id="raw-queries">Raw queries</a></h3>
<p>If this Query syntax is not enough for you, and you need to get your hands dirty on a raw SQL or Loki query, you need <strong>rawQueries</strong>. How to use them? Well, <strong>we need your help</strong> to finish this — <a href="https://github.com/Nozbe/WatermelonDB/pull/199">please contribute!</a> ❤️</p>
<h3><a class="header" href="#raw-queries" id="raw-queries">Raw Queries</a></h3>
<p>If this Query syntax is not enough for you, and you need to get your hands dirty on a raw SQL or Loki query, you need <strong>rawQueries</strong>. For now, only record SQL queries are available. If you need other SQL queries or LokiJS raw queries, please contribute!</p>
<pre><code class="language-js">const records = commentCollection.unsafeFetchRecordsWithSQL('select * from comments where ...')
</code></pre>
<p>Please don't use this if you don't know what you're doing. The method name is called <code>unsafe</code> for a reason. You need to be sure to properly sanitize user values to avoid SQL injection, and filter out deleted records using <code>where _status is not 'deleted'</code> clause</p>
<h3><a class="header" href="#null-behavior" id="null-behavior"><code>null</code> behavior</a></h3>
<p>There are some gotchas you should be aware of. The <code>Q.gt</code>, <code>gte</code>, <code>lt</code>, <code>lte</code>, <code>oneOf</code>, <code>notIn</code>, <code>like</code> operators match the semantics of SQLite in terms of how they treat <code>null</code>. Those are different from JavaScript.</p>
<p><strong>Rule of thumb:</strong> No null comparisons are allowed.</p>
Expand Down
14 changes: 11 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ <h4 align="center">
Build powerful React and React Native apps that scale from hundreds to tens of thousands of records and remain <em>fast</em> ⚡️
</p>
<p align="center">
<a href="https://opensource.org/licenses/MIT">
<a href="https://github.com/Nozbe/WatermelonDB/blob/master/LICENSE">
<img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="MIT License">
</a>
<a href="https://travis-ci.com/Nozbe/WatermelonDB">
Expand All @@ -175,7 +175,7 @@ <h4 align="center">
<tr><td></td><td>Fast. Async. Multi-threaded. Highly cached.</td></tr>
<tr><td>🔗</td><td>Relational. Built on rock-solid <a href="https://www.sqlite.org">SQLite</a> foundation</td></tr>
<tr><td>⚠️</td><td><strong>Static typing</strong> with <a href="https://flow.org">Flow</a> or <a href="https://typescriptlang.org">TypeScript</a></td></tr>
<tr><td>🔄</td><td><strong>Offline-first.</strong> <a href="docs/Advanced/Sync.html">Sync</a> with your own backend</td></tr>
<tr><td>🔄</td><td><strong>Offline-first.</strong> <a href="https://nozbe.github.io/WatermelonDB/Advanced/Sync.html">Sync</a> with your own backend</td></tr>
</tbody></table>
<h2><a class="header" href="#why-watermelon" id="why-watermelon">Why Watermelon?</a></h2>
<p><strong>WatermelonDB</strong> is a new way of dealing with user data in React Native and React web apps.</p>
Expand Down Expand Up @@ -241,13 +241,21 @@ <h2><a class="header" href="#who-uses-watermelondb" id="who-uses-watermelondb">W
</a>
<br>
<a href="https://steady.health">
<img src="https://github.com/Nozbe/WatermelonDB/raw/master/assets/apps/steady.png" alt="Steady">
<img src="https://github.com/Nozbe/WatermelonDB/raw/master/assets/apps/steady.png" alt="Steady" width="150">
</a>
<br>
<a href="https://aerobotics.com">
<img src="https://github.com/Nozbe/WatermelonDB/raw/master/assets/apps/aerobotics.png" alt="Aerobotics" width="300" />
</a>
<br>
<a href="https://smashappz.com">
<img src="https://github.com/Nozbe/WatermelonDB/raw/master/assets/apps/smashappz.jpg" alt="Smash Appz" width="300" />
</a>
<br>
<a href="https://rocket.chat/">
<img src="https://github.com/Nozbe/WatermelonDB/raw/master/assets/apps/rocketchat.png" alt="Rocket Chat" width="300" />
</a>
<br>
<p><em>Does your company or app use 🍉? Open a pull request and add your logo/icon with link here!</em></p>
<h2><a class="header" href="#contributing" id="contributing">Contributing</a></h2>
<img src="https://github.com/Nozbe/WatermelonDB/raw/master/assets/needyou.jpg" alt="We need you" width="220" />
Expand Down
Loading

0 comments on commit a838682

Please sign in to comment.