This is the full developer documentation for LiveStore. # Start of LiveStore documentation # [Docs](https://livestore.dev/docs//) ## Overview import { CardGrid, LinkCard } from '@astrojs/starlight/components'; ### Docs for LLMs We support the [llms.txt](https://llmstxt.org/) convention for making documentation available to large language models and the applications that make use of them. Currently, we have the following root-level files: - [/llms.txt](/llms.txt) — a listing of the available files - [/llms-full.txt](/llms-full.txt) — complete documentation for LiveStore # [Contributing](https://livestore.dev/docs/contributing/contributing/) ## Overview ## Before contributing First of all, thank you for your interest in contributing to LiveStore! Building LiveStore has been an incredible amount of work, so everyone interested in contributing is very much appreciated. 🧡 Please note that LiveStore is still in active development with many things yet subject to change (e.g. APIs, examples, docs, etc). Before you start contributing, please check with the maintainers if the changes you'd like to make are likely to be accepted. Please get in touch via the `#contrib` channel on [Discord](https://discord.gg/RbMcjUAPd7). ## Areas for contribution There are many ways to contribute to LiveStore. ### Help wanted for ... - You can look at ["help wanted" issues](https://github.com/livestorejs/livestore/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) on GitHub for ideas. - [SQLite WASM build](https://github.com/livestorejs/wa-sqlite) maintainer (e.g. keeping it up to date with upstream SQLite and wa-sqlite versions) - Examples maintainer (e.g. keeping dependencies & best practices up to date) - Solid integration maintainer (e.g. keeping it up to date with upstream Solid versions) ### In scope and encouraged - Documentation improvements - Improving examples - Test cases - Bug fixes - Benchmarking ### Potentially in scope - New features - Larger architectural changes in the core library - Adding new examples - Adding new integrations (e.g. for technologies such as Svelte, Vue, ...) - Monorepo setup changes - Changes to the docs site/setup ### Out of scope (for now) - Changes to the landing page - Changes to the devtools - Rewriting the core library in a different language ## Guiding principles {#guiding-principles} - Keep it as simple as possible - Reduce surface area - Make the right thing easy - Document the "why" # [Docs](https://livestore.dev/docs/contributing/docs/) ## Overview Please follow LiveStore's [guiding principles](/docs/contributing/contributing#guiding-principles) when writing docs. ## Writing style This project broadly tries to follow the [Prisma docs style guide](https://www.prisma.io/docs/about/style-guide/writing-style). ## Reusing code When including code snippets, please try to `import` the code from the source in order to avoid duplication. # [Monorepo](https://livestore.dev/docs/contributing/monorepo/) ## Overview import { REACT_VERSION, EFFECT_VERSION } from '../../../../../../CONSTANTS' ## Prerequisites ### Personal experience Depending on the kind of contribution you're interested in, the following experience is recommended: - Deep experience with TypeScript (incl. type-level programming) - Experience with TypeScript monorepo setups - Experience with distributed systems - Experience with [Effect](https://effect.website) (or willingness to learn) ### Recommended tooling: Use Nix + direnv for a consistent development setup To make development as easy and consistent across systems and platforms, this project uses [Nix](https://zero-to-nix.com/) to manage "system dependencies" such as Node.js, Bun etc. You can either use [Direnv](https://direnv.net) setup (recommended) to automatically load the Nix env or manually use the Nix env (e.g. via `nix develop --command pnpm install`). ### Manual setup You'll need to have a recent version the following tools installed: - Node.js - Bun - pnpm ## Initial setup ```bash git clone git@github.com:livestorejs/livestore.git cd livestore # Load environment variables (including Nix dependencies) direnv allow # Install dependencies pnpm install # Build the project pnpm build ``` ## General notes - TypeScript - LiveStore tries to follow the strictest TypeScript rules possible to ensure type safety and avoid subtle bugs. - LiveStore also makes heavy use of [TypeScript project references](https://www.typescriptlang.org/docs/handbook/project-references.html). - Package management - This project uses [pnpm](https://pnpm.io/) to manage the workspace. - LiveStore is primarily developed in VSCode/Cursor. - Testing - LiveStore uses Vitest for most tests and Playwright for browser tests. ### Notable used tools / technologies - [TypeScript](https://www.typescriptlang.org/) - [Effect](https://effect.website) - [pnpm](https://pnpm.io/) - [Bun](https://bun.sh/) - [Vitest](https://vitest.dev/) - [Playwright](https://playwright.dev/) - [OpenTelemetry](https://opentelemetry.io/) - [Nix](https://zero-to-nix.com/) - [Direnv](https://direnv.net/) ### Environment variables The `.envrc` file contains all necessary environment variables for the project. You can create a `.envrc.local` file to override or add variables for your local setup. You'll need to run `direnv allow` to load the environment variables. ### VSCode tasks - This project is primarily developed in VSCode and makes use of [tasks](https://code.visualstudio.com/docs/editor/tasks) to run commands. - Common tasks are: - `dev:ts` to run the TypeScript compiler in watch mode for the entire monorepo - `pnpm:install` to install all dependencies (e.g. when changing a `package.json`) ## Examples - Once you've set up the monorepo locally, you'll notice both the `src` and `standalone` directories in `/examples`. - The `/examples/standalone` directory is meant as a starting point for app developers evaluating LiveStore and looking for a ready-to-run example app. - The `/examples/src` directory is meant for LiveStore maintainers and to run as part of the LiveStore monorepo. Compared to `/examples/standalone` it makes use of local linking features such a `workspace:*`, TypeScript `references` etc. - Both directories are kept in sync via `/examples/patches` and `/scripts/generate-examples.ts`. Usually it's recommended to work in `/examples/src` and generate the `/examples/standalone` version via `pnpm -w generate:examples:standalone`. #### Making changes to examples 1. Make your desired changes in `/examples/src`. (You might also need to update some of the patches in `/examples/patches`.) 2. Run `pnpm generate:examples:standalone` to generate the `/examples/standalone` version 3. Check whether the changes in `/examples/standalone` are what you expected. 4. Commit your changes in both `/examples/src` and `/examples/standalone` (and possibly `/examples/patches`). Note on GitHub, changes to `examples/standalone` are hidden by default. ### OpenTelemetry setup As a local OpenTelemetry setup, we recommend the [docker-otel-lgtm](https://github.com/grafana/docker-otel-lgtm) setup. Add the following to your `.envrc.local` file: ```bash export VITE_GRAFANA_ENDPOINT="http://localhost:30003" export GRAFANA_ENDPOINT="http://localhost:30003" export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318" export VITE_OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318" ``` ### TypeScript - Each package has its own `tsconfig.json` file which extends the root `tsconfig.base.json`. - This project makes heavy use of TypeScript project references. ### Package management - This project uses [pnpm](https://pnpm.io/) to manage the workspace. - We're using the `workspace:*` protocol to link packages together. - We should try to keep dependencies to an absolute minimum and only add them if we absolutely need them. - We also need to manually add peer dependencies for each package. - We should try to avoid duplicate dependencies across the monorepo as much as possible as duplicate dependencies can lead to a lot of issues and pain. - We're also using the `resolutions` field in the root `package.json` to force some packages to be the same across the monorepo (ideally not needed but for some packages it's necessary currently). - We're using [syncpack](https://github.com/JamieMason/syncpack) to help maintain consistent dependency versions across the monorepo. - See `syncpack.config.mjs` for the configuration. - Common commands: - `bunx syncpack format` to format the `package.json` files - `bunx syncpack lint` to check all version ranges - `bunx syncpack fix-mismatches` to adjust versions across `package.json` files (check before with `lint`) - `bunx syncpack update` to update packages across the monorepo to the latest versions ### Notes on external dependencies LiveStore tries to use as few external dependencies as possible. Given LiveStore is built on top of Effect, which can be considered a standard library for TypeScript, it should handle most use cases. #### Notes on some packages The following packages need to be updated with extra care: - `react`/`react-dom` as we need to move in lockstep with Expo / React Native (currently pinned to {REACT_VERSION}) - `effect` (currently pinned to {EFFECT_VERSION}) #### Effect - LiveStore makes heavy use of the [Effect](https://effect.website) library and ecosystem throughout the implementation of the various packages. - Effect is not imposed on the app developers using LiveStore but where it makes sense, LiveStore is also exposing a Effect-based API (e.g. `createStore`). #### Updating dependencies - Either update the versions manually in each `package.json` file or use `bunx syncpack update`. ### Notes on monorepo structure - The `@livestore/utils` package re-exports many common modules/functions (e.g. from `effect`) in order to - Reduce the number of direct dependencies for other packages - Allows for convenient extension of modules (e.g. adding methods to `Effect.___`, `Schema.___`, ...) ## Docs The LiveStore docs are built with [Astro Starlight](https://starlight.astro.build/). ## Related external repos - [Fork of wa-sqlite](https://github.com/livestorejs/wa-sqlite) and its [Nix build setup](https://github.com/livestorejs/wa-sqlite-build-env?tab=readme-ov-file). - The source code of the devtools is currently not part of this monorepo but in a separate private repo. # [Design Decisions](https://livestore.dev/docs/evaluation/design-decisions/) ## Overview ## Goals - Fast, synchronous, transactional, and reactive state management - Global state is eventually consistent - Persistent storage - Syncing - Convenient schema migrations - Great devtools ## Major Design Decisions - Based on [event-sourcing](/docs/reference/event-sourcing) (implying a read/write model separation) - Using SQLite for state management over JavaScript implementations - There are many benefits to using SQLite for state management, including performance, reliability, and ease of use. - Run in-memory SQLite in main-thread to enable synchronous queries - Usually LiveStore is used with a second SQLite database for persistence running in a separate thread (e.g. web worker) - Running SQLite additionally in the main-thread however also means each tab uses extra memory. - The current implementation of LiveStore assumes that the data is small enough to fit in memory. However, SQLite is very efficient so this should work for many use cases and apps. - LiveStore implements a Signals-based reactivity system based on the ideas of Adapton for incremental computation - The goal is to keep LiveStore syncing provider agnostic so you can use the right syncing provider for your use case. ## Original motivation - Frustration with database schema migrations -> event sourcing to separate read and write model (avoid schema migrations for read model) - Applying the "Make the right thing easy" principle to app data management # [How LiveStore works](https://livestore.dev/docs/evaluation/how-livestore-works/) ## Overview ### TLDR LiveStore uses event sourcing to sync events across clients and materialize state as a local, reactive SQLite database. ![](https://share.cleanshot.com/dTpVv5K1+) ## Local state management ### SQLite ### Reactivity ### Persistence ## Syncing WIP. See [Syncing](/docs/reference/syncing/syncing) for more information. ### Sync backend ### Conflict resolution # [Performance benchmarks](https://livestore.dev/docs/evaluation/performance-benchmarks/) ## Overview Unfortunately, there isn't much to see here yet. Doing benchmarks right takes a lot of time and effort. LiveStore currently doesn't have enough resources to do this but anyone is welcome to contribute benchmarking results. In the future, it would be great to have benchmarks for: - end-to-end syncing (across sync backends) - should both show latency and throughput - boot time (across platforms) - both for initial app open and reopens - local reactivity (across framework integrations) - Should be mostly on par with other cutting edge frameworks - see [js-framework-benchmark](https://github.com/krausest/js-framework-benchmark) # [State of the project](https://livestore.dev/docs/evaluation/state-of-the-project/) ## Overview LiveStore is based on years of research (see [Riffle](https://riffle.systems/essays/prelude/)) and is used as the foundation for ambitious apps such as [Overtone](https://overtone.pro). LiveStore has been in development since 2021 and is getting closer to a stable release. LiveStore is not yet ready for production use but can already be used during development. ## Current state - LiveStore is currently in *private early access* and available as an *alpha release*. - **private early access**: To keep the development sustainable and level of feedback manageable, LiveStore is currently only available in early access to GitHub sponsors. We plan to offer public access to LiveStore mid 2025. - **alpha release**: LiveStore is still under heavy development which includes breaking changes and database resets during version upgrades. We expect LiveStore to reach a relatively stable state (beta) in the first half of 2025 and aiming for a 1.0 release in 2026. ### On breaking changes While LiveStore is in alpha there can be two kinds of breaking changes: - Breaking API change - Storage format changes (whenever `liveStoreStorageFormatVersion` is updated) We try our best to minimize breaking changes and to provide a migration path whenever possible. ## Roadmap See [GitHub issues](https://github.com/livestorejs/livestore/issues) for more details. Get in touch if you have any questions or feedback. ### Short-term - Rebase syncing protocol [#195](https://github.com/livestorejs/livestore/issues/195) - More testing ### Mid-term - Support syncing in Expo adapter [#119](https://github.com/livestorejs/livestore/issues/119) - Performance improvements ### Long-term - Support more syncing backends - Support more framework integrations - Support more platforms (e.g. Electron, Tauri) # [Technology comparison](https://livestore.dev/docs/evaluation/technology-comparison/) ## Overview ## TLDR of LiveStore's USPs - Uses combination of reactive, in-memory + synced, persisted SQLite for instant, synchronous queries - Based on event-sourcing methodologies - Client-centric (with great devtools) ## Other technologies - ElectricSQL - Automerge - YJS - Replicache / ZeroSync - JazzTools - TinyBase - Prisma ## Other state management libraries - Zustand - Redux / Redux Toolkit (RTK) - MobX - Jotai - Xstate - Recoil - React Query # [When to use LiveStore (and when not)](https://livestore.dev/docs/evaluation/when-livestore/) ## Overview - Choosing a data layer for a local-first app is a big decision and should be considered carefully. - On a high level, LiveStore can be a good fit if ... - you are looking for a principled data layer that works across platforms - you want to use SQLite for your queries - you like [event sourcing](/docs/reference/event-sourcing) to model data changes - you are working on a new app as LiveStore doesn't yet provide a way to [re-use an existing database](/docs/misc/faq#existing-database) - the current [state of the project](/docs/evaluation/state-of-the-project) aligns with your own timeline and requirements ## Database - All the client app data should fit into a in-memory SQLite database - Depending on the target device having databases up to 1GB in size should be okay. - If you you have more data, you can consider segmenting your database into multiple SQLite database (e.g. segmented per project, workspace, document, ...). - You can either use the `storeId` option for the segmentation or there could also be a way to use the [SQLite attach feature](https://www.sqlite.org/lang_attach.html) to dynamically attach/detach databases. ## Reasons not to choose LiveStore for your application - You want to build a more traditional client-server application with your primary data source being a remote server. - You want a full-stack batteries-included solution (e.g. auth, storage, etc.). Technologies like [Jazz](https://jazz.tools) or [Instant](https://instantdb.com) might be a better fit. - You don't like to model your data via read-write model separation/event sourcing or the trade-offs it involves. - You're a new developer and are just getting started. LiveStore is a relatively advanced technology with many design trade-offs that might make most sense after you have already experienced some of the problems LiveStore is trying to solve. ## Other considerations - How data flows / what's the source of truth? ## Syncing - LiveStore's syncing system is designed for small/medium-level concurrency scenarios (e.g. 10s / low 100s of users collaborating on the same thing for a given eventlog). - Collaboration on multiple different eventlogs concurrently is supported and should be used to "scale horizontally". # [Expo](https://livestore.dev/docs/getting-started/expo/) ## Overview import { Code, Steps, Tabs, TabItem } from '@astrojs/starlight/components' import babelConfigCode from '../../../../../../examples/standalone/expo-todomvc/babel.config.js?raw' import metroConfigCode from '../../../../../../examples/standalone/expo-todomvc/metro.config.js?raw' import eventsCode from '../../../../../../examples/standalone/expo-todomvc/src/livestore/events.ts?raw' import schemaCode from '../../../../../../examples/standalone/expo-todomvc/src/livestore/schema.ts?raw' import rootCode from '../../../../../../examples/standalone/expo-todomvc/src/Root.tsx?raw' import headerCode from '../../../../../../examples/standalone/expo-todomvc/src/components/NewTodo.tsx?raw' import mainSectionCode from '../../../../../../examples/standalone/expo-todomvc/src/components/ListTodos.tsx?raw' export const CODE = { babelConfig: babelConfigCode, metroConfig: metroConfigCode, schema: schemaCode, root: rootCode, header: headerCode, mainSection: mainSectionCode, } ### Prerequisites To use [LiveStore](/) with [Expo](https://docs.expo.dev/), ensure your project has the [New Architecture](https://docs.expo.dev/guides/new-architecture/) enabled. This is required for transactional state updates. ### Option A: Quick start For a quick start we recommend using our template app following the steps below. For existing projects see [Existing project setup](#existing-project-setup). 1. **Set up project from template** ```bash bunx tiged --mode=git git@github.com:livestorejs/livestore/examples/standalone/expo-todomvc my-app ``` Replace `my-app` with your desired app name. 2. **Install dependencies** It's strongly recommended to use `bun` or `pnpm` for the simplest and most reliable dependency setup (see [note on package management](/docs/misc/package-management) for more details). ```bash bun install ``` ```bash pnpm install --node-linker=hoisted ``` Make sure to use `--node-linker=hoisted` when installing dependencies in your project or add it to your `.npmrc` file. ``` # .npmrc nodeLinker=hoisted ``` Hopefully Expo will also support non-hoisted setups in the future. ```bash npm install ``` When using `yarn`, make sure you're using Yarn 4 or higher with the `node-modules` linker. ```bash yarn set version stable yarn config set nodeLinker node-modules yarn install ``` Pro tip: You can use [direnv](https://direnv.net/) to manage environment variables. 3. **Run the app** `bun ios` or `bun android` `pnpm ios` or `pnpm android` `npm run ios` or `npm run android` `yarn ios` or `yarn android` ### Option B: Existing project setup \{#existing-project-setup\} 1. **Install dependencies** ```bash bunx expo install @livestore/devtools-expo @livestore/adapter-expo @livestore/livestore @livestore/react @livestore/utils @livestore/peer-deps expo-sqlite ``` 2. **Add Vite meta plugin to babel config file** LiveStore Devtools uses Vite. This plugin emulates Vite's `import.meta.env` functionality. `bun add -d babel-plugin-transform-vite-meta-env` `pnpm add -D babel-plugin-transform-vite-meta-env` `yarn add -D babel-plugin-transform-vite-meta-env` `npm install --save-dev babel-plugin-transform-vite-meta-env` In your `babel.config.js` file, add the plugin as follows: 3. **Update Metro config** Add the following code to your `metro.config.js` file: ## Events Create a file named `events.ts` inside the `livestore` folder. This file stores the events your app uses to interact with the database. Use the `Events` and `Schema` modules from `@livestore/livestore` to define your events. Here's an example: ## Define your schema To define the data structure for your app, set up a schema that specifies the tables and fields your app uses. - In `src`, create a `livestore` folder and inside it create a file named `schema.ts`. This file defines the tables and data structures for your app. - In `schema.ts`, define a table to represent a data model, such as a `todos`. Here's an example: ## Add the LiveStore Provider To make the LiveStore available throughout your app, wrap your app's root component with the `LiveStoreProvider` component from `@livestore/react`. This provider manages your app’s data store, loading, and error states. ## Add the LiveStore Provider To make the LiveStore available throughout your app, wrap your app's root component with the `LiveStoreProvider` component from `@livestore/react`. This provider manages your app’s data store, loading, and error states. Here's an example: ### Commit events After wrapping your app with the `LiveStoreProvider`, you can use the `useStore` hook from any component to commit events. Here's an example: ## Queries To retrieve data from the database, first define a query using `queryDb` from `@livestore/livestore`. Then, execute the query with the `useQuery` hook from `@livestore/react`. Consider abstracting queries into a separate file to keep your code organized, though you can also define them directly within components if preferred. Here's an example: ## Devtools To open the devtools, run the app and from your terminal press `shift + m`, then select LiveStore Devtools and press `Enter`. ![Expo Terminal Screenshot](../../../../assets/devtools-terminal-expo.png) This will open the devtools in a new tab in your default browser. ![Devtools Browser Screenshot](../../../../assets/devtools-browser-view.png) Use the devtools to inspect the state of your LiveStore database, execute events, track performance, and more. ## Database location ### With Expo Go To open the database in Finder, run the following command in your terminal: ```bash open $(find $(xcrun simctl get_app_container booted host.exp.Exponent data) -path "*/Documents/ExponentExperienceData/*livestore-expo*" -print -quit)/SQLite ``` ### With development builds For development builds, the app SQLite database is stored in the app's Library directory. Example: `/Users//Library/Developer/CoreSimulator/Devices//data/Containers/Data/Application//Documents/SQLite/app.db` To open the database in Finder, run the following command in your terminal: ```bash open $(xcrun simctl get_app_container booted [APP_BUNDLE_ID] data)/Documents/SQLite ``` Replace `[APP_BUNDLE_ID]` with your app's bundle ID. e.g. `dev.livestore.livestore-expo`. ## Further notes - LiveStore doesn't yet support Expo Web (see [#130](https://github.com/livestorejs/livestore/issues/130)) # [Node](https://livestore.dev/docs/getting-started/node/) ## Overview TODO # [React Web](https://livestore.dev/docs/getting-started/react-web/) ## Overview import { Steps, Tabs, TabItem, Code } from '@astrojs/starlight/components'; import viteConfigCode from '../../../../../../examples/standalone/web-todomvc/vite.config.js?raw' import eventsCode from '../../../../../../examples/standalone/web-todomvc/src/livestore/events.ts?raw' import schemaCode from '../../../../../../examples/standalone/web-todomvc/src/livestore/schema.ts?raw' import workerCode from '../../../../../../examples/standalone/web-todomvc/src/livestore/livestore.worker.ts?raw' import rootCode from '../../../../../../examples/standalone/web-todomvc/src/Root.tsx?raw' import headerCode from '../../../../../../examples/standalone/web-todomvc/src/components/Header.tsx?raw' import mainSectionCode from '../../../../../../examples/standalone/web-todomvc/src/components/MainSection.tsx?raw' export const CODE = { viteConfig: viteConfigCode, events: eventsCode, schema: schemaCode, worker: workerCode, root: rootCode, header: headerCode, mainSection: mainSectionCode, } ### Option A: Quick start For a quick start, we recommend using our template app following the steps below. For existing projects, see [Existing project setup](#existing-project-setup). 1. **Set up project from template** ```shell bunx tiged --mode=git git@github.com:livestorejs/livestore/examples/standalone/web-linearlite my-app ``` Replace `my-app` with your desired app name. 2. **Install dependencies** It's strongly recommended to use `bun` or `pnpm` for the simplest and most reliable dependency setup (see [note on package management](/docs/misc/package-management) for more details). ```bash bun install ``` ```bash pnpm install ``` ```bash npm install ``` Pro tip: You can use [direnv](https://direnv.net/) to manage environment variables. 3. **Run dev environment** ```shell bun dev ``` ```shell pnpm dev ``` ```shell npm run dev ``` 4. **Open browser** Open `http://localhost:60000` in your browser. You can also open the devtools by going to `http://localhost:60000/_livestore`. ### Option B: Existing project setup \{#existing-project-setup\} 1. **Install dependencies** ```shell bun add @livestore/livestore @livestore/wa-sqlite @livestore/adapter-web @livestore/react @livestore/utils @livestore/peer-deps @livestore/devtools-vite ``` ```shell pnpm add @livestore/livestore @livestore/wa-sqlite @livestore/adapter-web @livestore/react @livestore/utils @livestore/peer-deps @livestore/devtools-vite ``` ```shell npm install @livestore/livestore @livestore/wa-sqlite @livestore/adapter-web @livestore/react @livestore/utils @livestore/peer-deps @livestore/devtools-vite ``` 2. **Update Vite config** Add the following code to your `vite.config.js` file: ## Events Create a file named `events.ts` inside the `livestore` folder. This file stores the events your app uses to interact with the database. Use the `Events` and `Schema` modules from `@livestore/livestore` to define your events. Here's an example: ## Define your schema To define the data structure for your app, set up a schema that specifies the tables and fields your app uses. - In `src`, create a `livestore` folder and inside it create a file named `schema.ts`. This file defines the tables and data structures for your app. - In `schema.ts`, define a table to represent a data model, such as a `todos`. Here's an example: ## Create the LiveStore Worker Create a file named `livestore.worker.ts` inside the `src/livestore` folder. This file will contain the LiveStore web worker. When importing this file, make sure to add the `?worker` extension to the import path to ensure that Vite treats it as a worker file. ## Add the LiveStore Provider To make the LiveStore available throughout your app, wrap your app's root component with the `LiveStoreProvider` component from `@livestore/react`. This provider manages your app’s data store, loading, and error states. Here's an example: ### Commit events After wrapping your app with the `LiveStoreProvider`, you can use the `useStore` hook from any component to commit events. Here's an example: ## Queries To retrieve data from the database, first define a query using `queryDb` from `@livestore/livestore`. Then, execute the query with the `useQuery` hook from `@livestore/react`. Consider abstracting queries into a separate file to keep your code organized, though you can also define them directly within components if preferred. Here's an example: # [Code of Conduct](https://livestore.dev/docs/misc/CODE_OF_CONDUCT/) ## Overview ## Our Pledge We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation. We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. ## Our Standards Examples of behavior that contributes to a positive environment for our community include: * Demonstrating empathy and kindness toward other people * Being respectful of differing opinions, viewpoints, and experiences * Giving and gracefully accepting constructive feedback * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience * Focusing on what is best not just for us as individuals, but for the overall community Examples of unacceptable behavior include: * The use of sexualized language or imagery, and sexual attention or advances of any kind * Trolling, insulting or derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or email address, without their explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Enforcement Responsibilities Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. ## Scope This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official email address, posting via an official social media account, or acting as an appointed representative at an online or offline event. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [contact@livestore.dev][Contact]. All complaints will be reviewed and investigated promptly and fairly. All community leaders are obligated to respect the privacy and security of the reporter of any incident. ## Enforcement Guidelines Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: ### 1. Correction **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. ### 2. Warning **Community Impact**: A violation through a single incident or series of actions. **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. ### 3. Temporary Ban **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. ### 4. Permanent Ban **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. **Consequence**: A permanent ban from any sort of public interaction within the community. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][Homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations][Translations]. [Homepage]: https://www.contributor-covenant.org [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html [Mozilla CoC]: https://github.com/mozilla/diversity [FAQ]: https://www.contributor-covenant.org/faq [Translations]: https://www.contributor-covenant.org/translations [Contact]: mailto:contact@livestore.dev # [Frequently Asked Questions](https://livestore.dev/docs/misc/FAQ/) ## Overview ## Can I use an ORM or query builder with LiveStore? It's possible to use most ORMs/query builders with LiveStore (as long as they are able to synchronously generate SQL statements). You should also give the built-in LiveStore query builder a try. ## Is there a company behind LiveStore? How does LiveStore make money? LiveStore is developed by [Johannes Schickling](https://github.com/schickling) and has been incubated as the foundation of [Overtone](https://overtone.pro) (a local-first music app). The plan is to keep the development of LiveStore as sustainable as possible via sponsorships and other paths (e.g. commercial licenses, paid consulting, premium devtools, etc). ## Is there a hosted sync backend provided by LiveStore? No, LiveStore is designed to be self-hosted or be used with a 3rd party sync backend. ## Can I use my existing database with LiveStore? {#existing-database} # [Community](https://livestore.dev/docs/misc/community/) ## Overview import { DISCORD_INVITE_URL } from '../../../../../../CONSTANTS.js' import { officeHours } from '../../../../../data.js' ## Discord You can join the Discord server here. ## Office hours { officeHours.map((url) => (