### Full TinyBase Setup and useQueries Example Source: https://tinybase.org/api/ui-solid/functions/queries-primitives/usequeries This example demonstrates a complete setup of TinyBase objects including store, metrics, indexes, relationships, and queries. It then shows how to use the `useQueries` primitive within a SolidJS reactive root. ```typescript import {createRoot} from 'solid-js'; import { createCheckpoints, createIndexes, createMetrics, createQueries, createRelationships, createStore, } from 'tinybase'; import {useQueries} from 'tinybase/ui-solid'; createRoot((dispose) => { const store = createStore() .setTables({ pets: {fido: {species: 'dog', color: 'brown', next: 'felix'}, felix: {species: 'cat', color: 'black'}, }, species: {dog: {price: 5}, cat: {price: 4}}, }) .setValues({open: true}); const metrics = createMetrics(store).setMetricDefinition( 'highestPrice', 'species', 'max', 'price', ); const indexes = createIndexes(store).setIndexDefinition( 'bySpecies', 'pets', 'species', ); const relationships = createRelationships(store) .setRelationshipDefinition('petSpecies', 'pets', 'species', 'species') .setRelationshipDefinition('nextPet', 'pets', 'pets', 'next'); const queries = createQueries(store).setQueryDefinition( 'petColors', 'pets', ({select, where, param}) => { select('color'); where((getCell) => getCell('species') == param('species')); }, {species: 'dog'}, ); const checkpoints = createCheckpoints(store); store.setCell('pets', 'fido', 'color', 'walnut'); checkpoints.setCheckpoint('updated color'); metrics.getMetric('highestPrice'); indexes.getSliceIds('bySpecies'); relationships.getRemoteRowId('petSpecies', 'fido'); queries.getResultRowIds('petColors'); useQueries(); dispose(); }); ``` -------------------------------- ### Full Example: Creating and Mounting App with Indexes Source: https://tinybase.org/api/ui-svelte/functions/provider/provideindexes This comprehensive example shows the complete setup, including creating a TinyBase store and indexes, then mounting the Svelte application to test the `provideIndexes` functionality. ```javascript import {flushSync, mount} from 'svelte'; import {createIndexes, createStore} from 'tinybase'; import App from './App.svelte'; const store = createStore().setCell('pets', 'fido', 'species', 'dog'); const indexes = createIndexes(store).setIndexDefinition( 'bySpecies', 'pets', 'species', ); const app = document.body.appendChild(document.createElement('div')); flushSync(() => mount(App, {target: app, props: {indexes}})); flushSync(); console.log(app.textContent); // -> ' ["registered"]' ``` -------------------------------- ### Tinybase Setup and Component Mount Example Source: https://tinybase.org/api/ui-svelte/functions/getter/getslicerowids This example sets up a Tinybase store and indexes, then mounts a Svelte component that uses getSliceRowIds. It logs the component's output to the console. ```javascript import {flushSync, mount} from 'svelte'; import {createIndexes, createStore} from 'tinybase'; import App from './App.svelte'; const store = createStore() .setTables({ pets: {fido: {species: 'dog', color: 'brown', sold: false, next: 'felix'}, felix: {species: 'cat', color: 'black', sold: true}, }, species: {dog: {price: 5}, cat: {price: 4}}, }) .setValues({open: true, employees: 3}); const indexes = createIndexes(store).setIndexDefinition( 'bySpecies', 'pets', 'species', ); const app = document.body.appendChild(document.createElement('div')); flushSync(() => mount(App, {target: app, props: {indexes}})); console.log(app.textContent); // -> '["fido"]' ``` -------------------------------- ### Initialize and Mount TinyBase App with Metrics Source: https://tinybase.org/api/ui-svelte/functions/getter/getmetrics This example demonstrates the complete setup for a TinyBase application using Svelte. It includes creating the store, metrics, mounting the app, and verifying the output. Use this for integration testing or initial setup. ```javascript import {flushSync, mount} from 'svelte'; import {createMetrics, createStore} from 'tinybase'; import App from './App.svelte'; const store = createStore().setCell('pets', 'fido', 'species', 'dog'); const metrics = createMetrics(store).setMetricDefinition( 'petCount', 'pets', 'count', ); const app = document.body.appendChild(document.createElement('div')); flushSync(() => mount(App, {target: app, props: {metrics}})); console.log(app.textContent); // -> '1' ``` -------------------------------- ### Setting up TinyBase and `getIndexStoreTableId` Example Source: https://tinybase.org/api/ui-svelte/functions/getter/getindexstoretableid This snippet shows the complete setup for the `getIndexStoreTableId` example, including creating a TinyBase store, defining an index, and mounting a Svelte component. It logs the resulting table ID to the console. ```javascript import {flushSync, mount} from 'svelte'; import {createIndexes, createStore} from 'tinybase'; import App from './App.svelte'; const store = createStore() .setTables({ pets: {fido: {species: 'dog', color: 'brown', sold: false, next: 'felix'}, felix: {species: 'cat', color: 'black', sold: true}, }, species: {dog: {price: 5}, cat: {price: 4}}, }) .setValues({open: true, employees: 3}); const indexes = createIndexes(store).setIndexDefinition( 'bySpecies', 'pets', 'species', ); const app = document.body.appendChild(document.createElement('div')); flushSync(() => mount(App, {target: app, props: {indexes}})); console.log(app.textContent); // -> 'pets' ``` -------------------------------- ### Full Example with TinyBase Setup and useIndexes Source: https://tinybase.org/api/ui-solid/functions/indexes-primitives/useindexes This example demonstrates setting up various TinyBase objects (store, metrics, indexes, relationships, queries, checkpoints) and then using the useIndexes primitive within a SolidJS reactive root. It shows how to initialize and interact with TinyBase data structures. ```typescript import {createRoot} from 'solid-js'; import { createCheckpoints, createIndexes, createMetrics, createQueries, createRelationships, createStore, } from 'tinybase'; import {useIndexes} from 'tinybase/ui-solid'; createRoot((dispose) => { const store = createStore() .setTables({ pets: {fido: {species: 'dog', color: 'brown', next: 'felix'}, felix: {species: 'cat', color: 'black'}, }, species: {dog: {price: 5}, cat: {price: 4}}, }) .setValues({open: true}); const metrics = createMetrics(store).setMetricDefinition( 'highestPrice', 'species', 'max', 'price', ); const indexes = createIndexes(store).setIndexDefinition( 'bySpecies', 'pets', 'species', ); const relationships = createRelationships(store) .setRelationshipDefinition('petSpecies', 'pets', 'species', 'species') .setRelationshipDefinition('nextPet', 'pets', 'pets', 'next'); const queries = createQueries(store).setQueryDefinition( 'petColors', 'pets', ({select, where, param}) => { select('color'); where((getCell) => getCell('species') == param('species')); }, {species: 'dog'}, ); const checkpoints = createCheckpoints(store); store.setCell('pets', 'fido', 'color', 'walnut'); checkpoints.setCheckpoint('updated color'); metrics.getMetric('highestPrice'); indexes.getSliceIds('bySpecies'); relationships.getRemoteRowId('petSpecies', 'fido'); queries.getResultRowIds('petColors'); useIndexes(); dispose(); }); ``` -------------------------------- ### SolidJS Example with RowView and TinyBase Setup Source: https://tinybase.org/api/ui-solid/functions/store-components/rowview This example demonstrates setting up a TinyBase store with tables, values, metrics, indexes, relationships, and queries. It then uses the RowView component within a SolidJS createRoot context to render a specific row. ```typescript import {createRoot} from 'solid-js'; import { createCheckpoints, createIndexes, createMetrics, createQueries, createRelationships, createStore, } from 'tinybase'; import {RowView} from 'tinybase/ui-solid'; createRoot((dispose) => { const store = createStore() .setTables({ pets: { fido: {species: 'dog', color: 'brown', next: 'felix'}, felix: {species: 'cat', color: 'black'}, }, species: {dog: {price: 5}, cat: {price: 4}}, }) .setValues({open: true}); const metrics = createMetrics(store).setMetricDefinition( 'highestPrice', 'species', 'max', 'price', ); const indexes = createIndexes(store).setIndexDefinition( 'bySpecies', 'pets', 'species', ); const relationships = createRelationships(store) .setRelationshipDefinition('petSpecies', 'pets', 'species', 'species') .setRelationshipDefinition('nextPet', 'pets', 'pets', 'next'); const queries = createQueries(store).setQueryDefinition( 'petColors', 'pets', ({select, where, param}) => { select('color'); where((getCell) => getCell('species') == param('species')); }, {species: 'dog'}, ); const checkpoints = createCheckpoints(store); store.setCell('pets', 'fido', 'color', 'walnut'); checkpoints.setCheckpoint('updated color'); metrics.getMetric('highestPrice'); indexes.getSliceIds('bySpecies'); relationships.getRemoteRowId('petSpecies', 'fido'); queries.getResultRowIds('petColors'); RowView({tableId: 'pets', rowId: 'fido', store}); dispose(); }); ``` -------------------------------- ### Setting up TinyBase and `getResultRowCount` Example Source: https://tinybase.org/api/ui-svelte/functions/getter/getresultrowcount This snippet shows the complete setup for the `getResultRowCount` example, including creating a TinyBase store, defining queries, mounting a Svelte component, and logging the output. It verifies that the row count is correctly displayed. ```javascript import {flushSync, mount} from 'svelte'; import {createQueries, createStore} from 'tinybase'; import App from './App.svelte'; const store = createStore() .setTables({ pets: {fido: {species: 'dog', color: 'brown', sold: false, next: 'felix'}, felix: {species: 'cat', color: 'black', sold: true}, }, species: {dog: {price: 5}, cat: {price: 4}}, }) .setValues({open: true, employees: 3}); const queries = createQueries(store).setQueryDefinition( 'petColors', 'pets', ({select}) => select('color'), ); const app = document.body.appendChild(document.createElement('div')); flushSync(() => mount(App, {target: app, props: {queries}})); console.log(app.textContent); // -> '2' ``` -------------------------------- ### SliceView Example with TinyBase Setup Source: https://tinybase.org/api/ui-solid/functions/indexes-components/sliceview This example demonstrates setting up TinyBase objects and using the SliceView component within a SolidJS reactive root. It includes creating a store, metrics, indexes, relationships, queries, and checkpoints, then updating a cell and rendering a SliceView. ```typescript import {createRoot} from 'solid-js'; import { createCheckpoints, createIndexes, createMetrics, createQueries, createRelationships, createStore, } from 'tinybase'; import {SliceView} from 'tinybase/ui-solid'; createRoot((dispose) => { const store = createStore() .setTables({ pets: {fido: {species: 'dog', color: 'brown', next: 'felix'}, felix: {species: 'cat', color: 'black'}, }, species: {dog: {price: 5}, cat: {price: 4}}, }) .setValues({open: true}); const metrics = createMetrics(store).setMetricDefinition( 'highestPrice', 'species', 'max', 'price', ); const indexes = createIndexes(store).setIndexDefinition( 'bySpecies', 'pets', 'species', ); const relationships = createRelationships(store) .setRelationshipDefinition('petSpecies', 'pets', 'species', 'species') .setRelationshipDefinition('nextPet', 'pets', 'pets', 'next'); const queries = createQueries(store).setQueryDefinition( 'petColors', 'pets', ({select, where, param}) => { select('color'); where((getCell) => getCell('species') == param('species')); }, {species: 'dog'}, ); const checkpoints = createCheckpoints(store); store.setCell('pets', 'fido', 'color', 'walnut'); checkpoints.setCheckpoint('updated color'); metrics.getMetric('highestPrice'); indexes.getSliceIds('bySpecies'); relationships.getRemoteRowId('petSpecies', 'fido'); queries.getResultRowIds('petColors'); SliceView({indexId: 'bySpecies', sliceId: 'dog', indexes}); dispose(); }); ``` -------------------------------- ### useCheckpoint Example with TinyBase Setup Source: https://tinybase.org/api/ui-solid/functions/checkpoints-primitives/usecheckpoint This example demonstrates setting up various TinyBase objects (store, metrics, indexes, relationships, queries, checkpoints) and then using the `useCheckpoint` primitive within a SolidJS reactive root. It shows how to create and interact with these objects and register a checkpoint. ```typescript import {createRoot} from 'solid-js'; import { createCheckpoints, createIndexes, createMetrics, createQueries, createRelationships, createStore, } from 'tinybase'; import {useCheckpoint} from 'tinybase/ui-solid'; createRoot((dispose) => { const store = createStore() .setTables({ pets: {fido: {species: 'dog', color: 'brown', next: 'felix'}}, felix: {species: 'cat', color: 'black'}, }) .setValues({open: true}); const metrics = createMetrics(store).setMetricDefinition( 'highestPrice', 'species', 'max', 'price', ); const indexes = createIndexes(store).setIndexDefinition( 'bySpecies', 'pets', 'species', ); const relationships = createRelationships(store) .setRelationshipDefinition('petSpecies', 'pets', 'species', 'species') .setRelationshipDefinition('nextPet', 'pets', 'pets', 'next'); const queries = createQueries(store).setQueryDefinition( 'petColors', 'pets', ({select, where, param}) => { select('color'); where((getCell) => getCell('species') == param('species')); }, {species: 'dog'}, ); const checkpoints = createCheckpoints(store); store.setCell('pets', 'fido', 'color', 'walnut'); checkpoints.setCheckpoint('updated color'); metrics.getMetric('highestPrice'); indexes.getSliceIds('bySpecies'); relationships.getRemoteRowId('petSpecies', 'fido'); queries.getResultRowIds('petColors'); useCheckpoint('0', checkpoints); dispose(); }); ``` -------------------------------- ### TinyBase in a Browser with CDN Source: https://tinybase.org/guides/the-basics/getting-started Include TinyBase from a CDN in an HTML file to quickly get started. This example demonstrates creating a store, setting a value and a cell, and then displaying them. ```html