# Trying to see when database content has changed.

**URL:** <https://talk.observablehq.com/t/trying-to-see-when-database-content-has-changed/3838>\
**Category:** Help\
**Created:** [September 5, 2020, 7:55am UTC](https://talk.observablehq.com/t/trying-to-see-when-database-content-has-changed/3838 "2020-09-05T07:55:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hellonearthis](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/hellonearthis/32/3935_2.png) [@hellonearthis](https://talk.observablehq.com/u/hellonearthis)\
**Post date:** [September 5, 2020, 7:55am UTC](https://talk.observablehq.com/t/trying-to-see-when-database-content-has-changed/3838/1 "2020-09-05T07:55:34Z")

</div>

Hi, I;m new to observable and I’m trying to work out how I would make this Loki database observable to see when items are added/deleted/changed.

Not sure where the viewof goes or if I would be plopping in yeild or mutable to expose the data.

Any help welcome.

> **[LokiJS database.](https://observablehq.com/@hellonearthis/lokijs-database)**
>
> An Observable notebook by Brett Cooper.

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [September 5, 2020, 4:20pm UTC](https://talk.observablehq.com/t/trying-to-see-when-database-content-has-changed/3838/2 "2020-09-05T16:20:58Z")

</div>

One of the ways you could approach this is to use Observable’s [mutable operator](https://observablehq.com/@observablehq/introduction-to-mutable-state), which lets you assign the value of a cell from another cell, and trigger any downstream cells with (non-mutable) references to that mutable cell to run again.

Here’s a suggestion that does that:

> **[Comparing ‘LokiJS database.’ by Brett Cooper to ‘LokiJS database.’ by Mike...](https://observablehq.com/compare/a0423eee08df1385@811...8f499b8d73617602@818)**
>
> A comparison of two Observable notebooks.

The basic steps are:

1. Any cell that wants to mutate your database references `mutable te_items` exclusively, and never `te_items` (otherwise, you’d likely get an infinite loop).
2. After the cell mutates the database, it reassigns `mutable te_items` to itself to trigger downstream cells to run. (It’s generally better to use a copy-on-write technique here similar to React state, but that’s not possible given that this database is inherently mutable.)
3. Any cell that you want to run automatically whenever `te_items` changes just references `te_items` as normal.
4. But, if a cell depends on a _specific_ mutation (such as the `find` cell depending on the `add_data` cell that inserts the _tyrfing_ record), that cell must include a reference to the cell that applies the mutation. That’s because Observable runs cells [in topological order](https://observablehq.com/@observablehq/how-observable-runs).

Hope this helps.

---

<div class="post-metadata">

**Author:** ![hellonearthis](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/hellonearthis/32/3935_2.png) [@hellonearthis](https://talk.observablehq.com/u/hellonearthis)\
**Post date:** [September 6, 2020, 2:16am UTC](https://talk.observablehq.com/t/trying-to-see-when-database-content-has-changed/3838/3 "2020-09-06T02:16:52Z")

</div>

> [@mbostock](#):
>
> The basic steps are:
> 
> 1. Any cell that wants to mutate your database references `mutable te_items` exclusively, and never `te_items` (otherwise, you’d likely get an infinite loop).
> 2. After the cell mutates the database, it reassigns `mutable te_items` to itself to trigger downstream cells to run. (It’s generally better to use a copy-on-write technique here similar to React state, but that’s not possible given that this database is inherently mutable.)
> 3. Any cell that you want to run automatically whenever `te_items` changes just references `te_items` as normal.
> 4. But, if a cell depends on a _specific_ mutation (such as the `find` cell depending on the `add_data` cell that inserts the _tyrfing_ record), that cell must include a reference to the cell that applies the mutation. That’s because Observable runs cells [in topological order](https://observablehq.com/@observablehq/how-observable-runs).
> 
> Hope this helps.

Thanks so much, that really helped a lot in my understanding of observable.
