update app create config to accept libsql config directly

This commit is contained in:
dswbx
2025-02-12 09:21:51 +01:00
parent f466dd166d
commit 2c6a4d2bed
20 changed files with 59 additions and 100 deletions

View File

@@ -43,12 +43,9 @@ export const prerender = false;
export const ALL = serve({
connection: {
type: "libsql",
config: {
// location of your local Astro DB
// make sure to use a remote URL in production
url: "file:.astro/content.db"
}
// location of your local Astro DB
// make sure to use a remote URL in production
url: "file:.astro/content.db"
}
});
```

View File

@@ -19,11 +19,8 @@ import { serve } from "bknd/adapter/bun";
// if the configuration is omitted, it uses an in-memory database
serve({
connection: {
type: "libsql",
config: {
url: process.env.DB_URL!,
authToken: process.env.DB_AUTH_TOKEN!
}
url: process.env.DB_URL!,
authToken: process.env.DB_AUTH_TOKEN!
}
});
```

View File

@@ -22,11 +22,8 @@ import { serve } from "bknd/adapter/cloudflare";
export default serve<Env>({
app: ({ env }) => ({
connection: {
type: "libsql",
config: {
url: env.DB_URL,
authToken: env.DB_TOKEN
}
url: env.DB_URL,
authToken: env.DB_TOKEN
}
})
});
@@ -83,11 +80,8 @@ import manifest from "__STATIC_CONTENT_MANIFEST";
export default serve<Env>({
app: ({ env }) => ({
connection: {
type: "libsql",
config: {
url: env.DB_URL,
authToken: env.DB_TOKEN
}
url: env.DB_URL,
authToken: env.DB_TOKEN
}
}),
onBuilt: async (app) => {

View File

@@ -20,11 +20,8 @@ export const config = {
export default serve({
connection: {
type: "libsql",
config: {
url: process.env.DB_URL!,
authToken: process.env.DB_AUTH_TOKEN!
}
url: process.env.DB_URL!,
authToken: process.env.DB_AUTH_TOKEN!
}
});
```

View File

@@ -20,10 +20,7 @@ import { serve } from "bknd/adapter/node";
/** @type {import("bknd/adapter/node").NodeAdapterOptions} */
const config = {
connection: {
type: "libsql",
config: {
url: ":memory:"
}
url: ":memory:"
}
};

View File

@@ -16,10 +16,7 @@ import { serve } from "bknd/adapter/remix";
const handler = serve({
connection: {
type: "libsql",
config: {
url: "http://localhost:8080"
}
url: "http://localhost:8080"
}
});

View File

@@ -26,10 +26,7 @@ import { serve } from "bknd/adapter/vite";
export default serve({
mode: "cached", // that's the default
connection: {
type: "libsql",
config: {
url: ":memory:"
}
url: ":memory:"
}
})
```

View File

@@ -18,10 +18,7 @@ The easiest to get started is using SQLite as a file. When serving the API in th
the function accepts an object with connection details. To use a file, use the following:
```json
{
"type": "libsql",
"config": {
"url": "file:<path/to/your/database.db>"
}
"url": "file:<path/to/your/database.db>"
}
```
Please note that using SQLite as a file is only supported in server environments.
@@ -36,10 +33,7 @@ turso dev
The command will yield a URL. Use it in the connection object:
```json
{
"type": "libsql",
"config": {
"url": "http://localhost:8080"
}
"url": "http://localhost:8080"
}
```
@@ -48,11 +42,8 @@ If you want to use LibSQL on Turso, [sign up for a free account](https://turso.t
connection object to your new database:
```json
{
"type": "libsql",
"config": {
"url": "libsql://your-database-url.turso.io",
"authToken": "your-auth-token"
}
"url": "libsql://your-database-url.turso.io",
"authToken": "your-auth-token"
}
```

View File

@@ -39,19 +39,16 @@ implements the `Fetch` API.
The `CreateAppConfig` type is the main configuration object for the `createApp` function. It has
the following properties:
```ts
import type { App, InitialModuleConfigs, ModuleBuildContext } from "bknd";
import type { Connection } from "bknd/data";
import type { Config } from "@libsql/client";
type AppPlugin = (app: App) => Promise<void> | void;
type LibSqlCredentials = Config;
type CreateAppConfig = {
connection?:
| Connection
| {
type: "libsql";
config: LibSqlCredentials;
};
| Config;
initialConfig?: InitialModuleConfigs;
plugins?: AppPlugin[];
options?: {
@@ -63,17 +60,12 @@ type CreateAppConfig = {
};
```
### `connection`
The `connection` property is the main connection object to the database. It can be either an
object with a type specifier (only `libsql` is supported at the moment) and the actual
`Connection` class. The `libsql` connection object looks like this:
The `connection` property is the main connection object to the database. It can be either an object with libsql config or the actual `Connection` class.
```ts
const connection = {
type: "libsql",
config: {
url: string;
authToken?: string;
};
url: "<url>",
authToken: "<token>"
}
```
@@ -168,6 +160,8 @@ but before its event is emitted. This is useful for adding custom routes or othe
A simple plugin that adds a custom route looks like this:
```ts
import type { AppPlugin } from "bknd";
export const myPlugin: AppPlugin = (app) => {
app.server.get("/hello", (c) => c.json({ hello: "world" }));
};