You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Guide/realtime-spas.markdown
+75Lines changed: 75 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -597,6 +597,81 @@ const todos = await query('todos').fetchAndRefresh(callback);
597
597
598
598
The `fetchAndRefresh`functionis using a websocket to be notified about any changes to the selected data set. [It's using IHP's `DataSubscription` API.](https://github.com/digitallyinduced/ihp/blob/master/lib/IHP/static/vendor/ihp-datasync.js) For more fine grained control you can use the `DataSubscription` API directly instead of relying on `fetchAndRefresh`.
599
599
600
+
#### Filtering
601
+
602
+
Filtering records works similar to normal IHP. In JavaScript you have the choice between `filterWhere` and `where` - the two functionwork identically.
// AND id = 'd94173ec-1d91-421e-8fdc-20a3161b7802'
630
+
```
631
+
632
+
##### Adding alternative conditions using `or`
633
+
634
+
You can also combine conditions using or with the `.or` function, which will take all previous conditions and allow any row to match that fulfills the alternative condition:
635
+
636
+
```javascript
637
+
// add this import
638
+
import { where } from 'ihp-datasync/ihp-querybuilder'
// WHERE id = 'd94173ec-1d91-421e-8fdc-20a3161b7802'
648
+
// OR id = '173ecd94-911d-1e42-dc8f-1b780320a316'
649
+
```
650
+
651
+
You can of course chain the conditions inside the `.or` call as well.
652
+
653
+
##### Adding additional conditions using `and`
654
+
655
+
In some cases you might want to add a combination of conditions to a query using `and` and doing so by chaining would be unclear. In that case, you can use the `.and`functionwhich functions identically to the `.or` function, except for of course combining the conditions using `AND`, not `OR`.
656
+
657
+
```javascript
658
+
// add this import
659
+
import { where } from 'ihp-datasync/ihp-querybuilder'
// WHERE user_id = '173ecd94-911d-1e42-dc8f-1b780320a316'
668
+
// AND (title = 'Test' OR title = 'test')
669
+
```
670
+
671
+
##### Checking for inequality
672
+
673
+
If you want to check forinequality instead of equality of a column value, you can use the `filterWhereNot` and `whereNot` functions. They work identically to their `filterWhere` and `where` counterparts and can be usedin any situation those functions can be used in.
674
+
600
675
#### Fetching a single record
601
676
602
677
When you have the id of a record, you can also use `fetchOne` to get it from the database:
0 commit comments