> ## Documentation Index
> Fetch the complete documentation index at: https://docs.jtbdos.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Switch to Turso

> How to change the database provider to Turso.

export const Authors = ({data}) => {
  const baseUrl = typeof window !== 'undefined' && window.location.origin.includes('localhost') ? '' : 'https://raw.githubusercontent.com/haydenbleasel/JTBDOS/refs/heads/main/docs';
  return <div style={{
    marginBottom: '3rem',
    display: 'flex',
    flexDirection: 'column',
    gap: '0.5rem'
  }}>
      <span style={{
    color: 'rgb(107, 114, 128)',
    fontSize: '0.875rem'
  }}>Co-authored by</span>
      <div style={{
    display: 'flex',
    flexWrap: 'wrap',
    alignItems: 'center',
    gap: '0.5rem'
  }}>
        {data.map(author => <div key={author.name} style={{
    padding: '0.75rem',
    paddingRight: '1rem',
    display: 'inline-flex',
    alignItems: 'center',
    gap: '0.75rem',
    fontWeight: 'normal',
    position: 'relative',
    ringWidth: '2px',
    ringColor: 'transparent',
    borderRadius: '0.75rem',
    backgroundColor: 'white',
    border: '1px solid rgba(0,0,0,0.1)',
    overflow: 'hidden'
  }}>
            <div style={{
    position: 'relative'
  }}>
              <div style={{
    overflow: 'hidden',
    border: '1px solid #e5e7eb',
    borderRadius: '9999px',
    width: '2rem',
    height: '2rem'
  }}>
                <img style={{
    margin: 0,
    width: '100%',
    height: '100%',
    objectFit: 'cover'
  }} src={`${baseUrl}/images/authors/${author.company.id}/${author.user.id}.jpg`} alt="" width={32} height={32} />
              </div>
              <div style={{
    position: 'absolute',
    border: '1px solid white',
    overflow: 'hidden',
    borderRadius: '9999px',
    objectFit: 'cover',
    width: '1rem',
    height: '1rem',
    right: '-0.25rem',
    bottom: '-0.25rem'
  }}>
                <img style={{
    margin: 0,
    width: '100%',
    height: '100%',
    objectFit: 'cover'
  }} src={`${baseUrl}/images/authors/${author.company.id}/logo.jpg`} alt="" width={16} height={16} />
              </div>
            </div>
            <div style={{
    display: 'flex',
    flexDirection: 'column'
  }}>
              <span style={{
    fontWeight: 600,
    lineHeight: 1.25,
    fontSize: '13px',
    letterSpacing: '-0.01em'
  }}>
                {author.user.name}
              </span>
              <span style={{
    color: 'rgb(107, 114, 128)',
    lineHeight: 1.25,
    fontSize: '11px'
  }}>
                {author.company.name}
              </span>
            </div>
          </div>)}
      </div>
    </div>;
};

<Authors
  data={[
{
  user: {
    name: "Hayden Bleasel",
    id: "haydenbleasel",
  },
  company: {
    name: "JTBDOS",
    id: "JTBDOS",
  },
},
{
  user: {
    name: "Jamie Barton",
    id: "notrab",
  },
  company: {
    name: "Turso",
    id: "turso",
  },
},
]}
/>

[Turso](https://turso.tech) is multi-tenant database platform built for all types of apps, including AI apps with on-device RAG, local-first vector search, offline writes, and privacy-focused data access with low latency.

Here's how to switch from Neon to [Turso](https://turso.tech) for your `JTBDOS` project.

## 1. Sign up to Turso

You can use the [Dashboard](https://app.turso.tech), or the [CLI](https://docs.turso.tech/cli) to manage your account, database, and auth tokens.

*We'll be using the CLI throughout this guide.*

## 2. Create a Database

Create a new database and give it a name using the Turso CLI:

```sh Terminal
turso db create <database-name>
```

You can now fetch the URL to the database:

```sh Terminal
turso db show <database-name> --url
```

It will look something like this:

```
libsql://<database-name>-<account-or-org-slug>.turso.io
```

## 3. Create a Database Auth Token

You will need to create an auth token to connect to your Turso database:

```sh Terminal
turso db tokens create <database-name>
```

## 4. Update your environment variables

Update your environment variables to use the new Turso connection string:

```js apps/database/.env
DATABASE_URL="libsql://<database-name>-<account-or-org-slug>.turso.io"
DATABASE_AUTH_TOKEN="..."
```

```js apps/app/.env.local
DATABASE_URL="libsql://<database-name>-<account-or-org-slug>.turso.io"
DATABASE_AUTH_TOKEN="..."
```

Etcetera.

Now inside `packages/env/index.ts`, add `DATABASE_AUTH_TOKEN` to the `server` and `runtimeEnv` objects:

```ts {3,12}
const server: Parameters<typeof createEnv>[0]["server"] = {
  // ...
  DATABASE_AUTH_TOKEN: z.string(),
  // ...
};

export const env = createEnv({
  client,
  server,
  runtimeEnv: {
    // ...
    DATABASE_AUTH_TOKEN: process.env.DATABASE_AUTH_TOKEN,
    // ...
  },
});
```

## 5. Install @libsql/client

The [`@libsql/client`](https://www.npmjs.com/@libsql/client) is used to connect to the hosted Turso database.

Uninstall the existing dependencies for Neon...

```sh Terminal
pnpm remove @neondatabase/serverless @prisma/adapter-neon ws @types/ws --filter @repo/database
```

... and install the new dependencies for Turso & libSQL:

```sh Terminal
pnpm add @libsql/client --filter @repo/database
```

## 6. Update Webpack configuration

Open `packages/next-config/index.ts` and add `@libsql/client` to the list of externals:

```ts packages/next-config/index.ts {5}
let nextConfig: NextConfig = {
  ...config,
  webpack: (config, { isServer }) => {
    if (isServer) {
      config.externals = [...(config.externals || []), "@libsql/client"];
    }

    // ...
  },
};
```

## 7. Update the database connection code

Open `packages/database/index.ts` and make the following changes:

```ts packages/database/index.ts
import "server-only";

import { createClient } from "@libsql/client";
import { env } from "@repo/env";

const libsql = createClient({
  url: env.DATABASE_URL,
  authToken: env.DATABASE_AUTH_TOKEN,
});

export const database = libsql;
```

## 8. Apply schema changes

Now connect to the Turso database using the CLI:

```sh Terminal
turso db shell <database-name>
```

And apply the schema to the database:

```sql
CREATE TABLE pages (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  email TEXT UNIQUE NOT NULL,
  name TEXT
);
```

## 9. Update application code

Now wherever you would usually call Prisma, use the `libsql` client instead:

```ts packages/app/app/(authenticated)/page.tsx
import { database } from "@repo/database";

type PageType = {
  id: number;
  email: string;
  name?: string;
};

// ...

const { rows } = await database.execute(`SELECT * FROM pages`);

const pages = rows as unknown as Array<PageType>;
```
