How do i use a database note? #10872
Replies: 2 comments
|
Great question — the two SQL-related note types serve very different purposes: SQL vs. SQLite (Trilium)
For your Pokémon card tracker, though, you probably don't want raw SQL notes. A better approach is to use a render note + a script note that stores per-cell state as JSON in a regular note's content:
The script would read and write state using A rough script pattern: // In your render script
const stateNoteId = "YOUR_STATE_NOTE_ID";
// Read state from backend
const stateJson = await api.runOnBackend((id) => {
return api.getNote(id).getContent();
}, [stateNoteId]);
const state = JSON.parse(stateJson || "{}");
// Build table, render cells based on state...
// On cell click, toggle state and persist:
async function toggleCell(key) {
state[key] = !state[key];
await api.runOnBackend((id, newState) => {
api.getNote(id).setContent(JSON.stringify(newState));
}, [stateNoteId, state]);
// Re-render the cell UI
}This approach gives you clickable toggling cells that persist across page loads, all within Trilium. The render note system supports full HTML/JS/CSS so you have complete control over the table styling [6]. To reply, just mention @dosu. Docs are dead. Just use Dosu. |
|
@DuckersMcQuack , why not use the Table collection? You can use a boolean promoted attribute, no scripting or database management required. |
Uh oh!
There was an error while loading. Please reload this page.
I want to make a table note where there's a red cell with a X in it, when clicked, it turns green with a checkmark, and i want to have a database note for that, but i couldn't figure out how to make that sql/sqlite-trilium note type properly for the table-note to write each cell's state into said database note. How do i properly set it up to do this? As i'm setting up a fancy table structure for each pokemon card series's sets and sub-sets, so it needs a database of sorts so i can properly update the lists with convenient clicks
And what's the difference between sql and sqlite-trilium? The SQL note would just be a "middle man" for a actual SQL docker that stores the states for instance?
All reactions