`useArray` is useful if you need to use `DataArray.groupBy` or other `DataArray`-specific functions
## Setup
## How is this installed?
Please see the external documentation for the most up to date version.
### Set up in Obsidian
Since Datacore is not in the official Obsidian plugins store, you must use the BRAT Obsidian plugin.
1. Go to `Settings -> Community Plugins -> Browse` , search for `BRAT` plugin
2. Download, and enable it.
3. Go to the plugin settings, and under the `Beta plugin list` section, click on the `Add beta plugin` button.
4. Paste in the URL of the GitHub repository, [https://github.com/blacksmithgu/datacore](https://github.com/blacksmithgu/datacore) , and click `Add Plugin` and make sure `Enable after installing the plugin` is checked.
Note that every time Obsidian is opened or restarted, it will take some time for Datacore to index all your files. Although it takes longer than Dataview, this initial preparation allows for 50x faster query load times during actual usage.
### How do they work?
The queries are stored as code, which we can render using code blocks.
#### What are some limitations?
##### Interactable elements for queries in callouts only work on preview mode
If you try clicking on any interactable query elements while viewing the note in edit mode, then it will instead start editing the callout.
This applies for things like:
- Using the bottom page navigation
- Clicking on a header to change the column sorting type
##### Clicking on row headers to sort in callouts only works on preview mode
If you try clicking on a header row of a query while viewing the note in edit mode, then it will instead start editing the callout.
### How can I modify them?
#### Page size
By default, it is set to 25. If you're experiencing performance issues, you can change the amount of results shown in the table in the plugin settings. However, we suggest having higher numbers if you would like to click on the table headers to modify the sorting criteria since it will only sort the notes currently shown.
#### Manually added configuration files
To make it easier for you to customize some of the values and settings of these Datacore scripts, some have an associated `Config` note. Instead of editing the code, you can just edit the metadata fields and code blocks in that file.
For example:
- For your wheel of life, you can simply edit the metadata fields in [[My Wheel Of Life Config]]
- [[My Habit Tracker]] has a config file [[My Habits Config]] that has code blocks for you to modify
To learn more about these configurations, you can read about the related notes in the USV documentation.
#### Other
Since this plugin is in early development, the main way to customize queries is by directly working with the Javascript code.
All files are stored in the `Hidden/Datacore` folder, but JS files are hidden in Obsidian, so you must view them using your file explorer.
Then, you can open the file using a text application like `Notepad++` or a code editor like `Visual Studio Code` (recommended).
For organization, each Datacore query map has its queries in its own file.
Each query has its own function and has three main things you may want to edit:
- `columns`, to modify the labels or values of columns
- `pages`, to change the query logic for choosing which files to find
- `sortedPages`, to change the way the files are sorted
If you want to make your own, you must create a new function and then add it to the `return` statement at the end of the list.
### How can I use them in other notes?
You can copy Datacore code blocks to use these queries in other places. Just be sure that the file path and name of the function being imported is correct:
````
```datacorejsx
// make sure file path is the correct one where the query is stored (ex. `maps.jsx`)
const { NotesCreatedThisWeek } = await dc.require("Hidden/Datacore/Views/Notes.jsx");
// also make sure name of the query (ex. NotesCreatedThisWeek) is correct here
return function View() {
return <NotesCreatedThisWeek/>;
}
```
````
### How can I learn more?
I suggest going to their documentation https://blacksmithgu.github.io/datacore/code-views#displaying-your-data, but the real magic and tinkering happens in their [Dataview and Datacore discord server](https://discord.gg/KwZUX4BYba).
## Features
- Should be using dc.useCurrentFile() when listening to metadata
- useMemo is going to be super important to prevent re-renders
- https://blacksmithgu.github.io/datacore/code-views#processing-your-data
- Pagination
- `paging={true}`
- 50x faster renders
- Can look for children/parents of other elements
- @block and childof(@section and $title = "name")
- `$row` is the field
- In query, access a spaced value via `$row["Knowledge Type"] = "Person"`
### Querying
#### List elements
- From an element
- `page.$sections` is sections
- then `page.$sections.$blocks` is all blocks
- then `page.$sections.$blocks.filter(block => block.$types.contains("block-list"))` is all markdown list blocks
- Also
- Can keep going deeper via `page.$elements`, until the child has `$text`, (list item)
- To get the parent can just access $file
### Problems
- If you don't see changes, this may take reloading the code block, note, or app
- No major customization options for queries yet?
- Long initial indexing times, happens on install and on full reload (re-opening, etc.)
- Took a while with 5000 notes
- No super optimized views as useCurrentFile listens to all metadata?
- Tags seem to have a slower update time when switching pages
- Section searching
- Most effective way seems to just embed for now
### Rendering
- Rendering content of a header/section
- https://discord.com/channels/1219902517304098836/1219902517304098841/1255724214258761778
- Should probably make helper functions to achieve something similar as well
- custom widths
- tagged blocks
- https://discord.com/channels/1219902517304098836/1253228164159897661/1256885552788279318
### Rerendering
https://discord.com/channels/1219902517304098836/1248851728137195591/1295189524208418888
on interval
```
const indexRevision = dc.useIndexUpdates({ debounce: 1000 });
useEffect(() => ā¦, [ref.current, indexRevision]);
```
or manual
```
const [generation, setGeneration] = dc.useState(0);
dc.useEffect(() => {
}, [ref.current, generation]);
return <>
<button onClick={() => setGeneration(gen => gen + 1)}>Refresh</button>
<div ref={ref}></div>;
</>;
```
## Implementation
- Currently exploring in [[Ultimate Starter Vault 2.5]]
- Auto-complete https://discord.com/channels/1219902517304098836/1248851728137195591/1303508145372532809
### Span Embeds
- If it has really effective indexing for text in headers then I might not even need in-line writing for some things
- Could be how you render things like sections and blocks
- [Discord message](https://discord.com/channels/1219902517304098836/1253228164159897661/1256885552788279318)
```
return function View() { const blocks = dc.useQuery(`@block and #tagged`); return <div> {blocks.map(block => ( <dc.SpanEmbed path={block.$file} start={block.$position.start} end={block.$position.end} /> ))} </div>; }
```
## Docs Reference
`local-api` has api that's accessible in scripts
`api` is for plugins that use it
### Accessing via plugin
```
const datacoreApi: any = plugin.app.plugins.plugins["datacore"].api;
const notes = datacoreApi.query('@page and exists("Knowledge Type")')
```
## Examples
### CRM
- https://www.reddit.com/r/ObsidianMD/comments/1hz5fcf/fully_functional_modular_crm/
- I like how the left view is custom
- I like the use of varying colors
- I like the way padding and margin is used, only showing key statistics
- I'm thinking of maybe doing something similar for my own homepages
- I think could be good inspiration and layout for some items
- https://stimmons.substack.com/p/building-a-powerful-habit-tracker?r=4wgoqh&triedRedirect=true