mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
small refactorings and cleanups, improved bun/node adapter, updated docs
This commit is contained in:
@@ -16,7 +16,8 @@ the admin panel.
|
||||
// index.ts
|
||||
import { serve } from "bknd/adapter/bun";
|
||||
|
||||
const handler = serve({
|
||||
// if the configuration is omitted, it uses an in-memory database
|
||||
serve({
|
||||
connection: {
|
||||
type: "libsql",
|
||||
config: {
|
||||
@@ -25,13 +26,6 @@ const handler = serve({
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Bun.serve({
|
||||
port: 1337,
|
||||
fetch: handler
|
||||
});
|
||||
|
||||
console.log("Server running at http://localhost:1337");
|
||||
```
|
||||
For more information about the connection object, refer to the [Setup](/setup) guide.
|
||||
|
||||
|
||||
37
docs/integration/node.mdx
Normal file
37
docs/integration/node.mdx
Normal file
@@ -0,0 +1,37 @@
|
||||
---
|
||||
title: 'Node'
|
||||
description: 'Run bknd inside Node'
|
||||
---
|
||||
import InstallBknd from '/snippets/install-bknd.mdx';
|
||||
|
||||
## Installation
|
||||
Install bknd as a dependency:
|
||||
<InstallBknd />
|
||||
|
||||
## Serve the API & static files
|
||||
The `serve` function of the Node adapter makes sure to also serve the static files required for
|
||||
the admin panel.
|
||||
|
||||
``` tsx
|
||||
// index.js
|
||||
import { serve } from "bknd/adapter/node";
|
||||
|
||||
// if the configuration is omitted, it uses an in-memory database
|
||||
/** @type {import("bknd/adapter/node").NodeAdapterOptions} */
|
||||
const config = {
|
||||
connection: {
|
||||
type: "libsql",
|
||||
config: {
|
||||
url: ":memory:"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
serve(config);
|
||||
```
|
||||
For more information about the connection object, refer to the [Setup](/setup) guide.
|
||||
|
||||
Run the application using node by executing:
|
||||
```bash
|
||||
node index.js
|
||||
```
|
||||
@@ -104,7 +104,7 @@
|
||||
"integration/vite",
|
||||
"integration/express",
|
||||
"integration/astro",
|
||||
"integration/nodejs",
|
||||
"integration/node",
|
||||
"integration/deno",
|
||||
"integration/browser"
|
||||
]
|
||||
|
||||
@@ -18,9 +18,9 @@ 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": "sqlite",
|
||||
"type": "libsql",
|
||||
"config": {
|
||||
"file": "path/to/your/database.db"
|
||||
"url": "file:<path/to/your/database.db>"
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -56,6 +56,30 @@ connection object to your new database:
|
||||
}
|
||||
```
|
||||
|
||||
### Custom Connection (unstable)
|
||||
<Note>
|
||||
Follow the progress of custom connections on its [Github Issue](https://github.com/bknd-io/bknd/issues/24).
|
||||
If you're interested, make sure to upvote so it can be prioritized.
|
||||
</Note>
|
||||
Any bknd app instantiation accepts as connection either `undefined`, a connection object like
|
||||
described above, or an class instance that extends from `Connection`:
|
||||
```ts
|
||||
import { createApp } from "bknd";
|
||||
import { Connection } from "bknd/data";
|
||||
|
||||
class CustomConnection extends Connection {
|
||||
constructor() {
|
||||
const kysely = new Kysely(/* ... */);
|
||||
super(kysely);
|
||||
}
|
||||
}
|
||||
|
||||
const connection = new CustomConnection();
|
||||
|
||||
// e.g. and then, create an instance
|
||||
const app = createApp({ connection })
|
||||
```
|
||||
|
||||
## Installation
|
||||
To install **bknd**, run the following command:
|
||||
<InstallBknd />
|
||||
Reference in New Issue
Block a user