mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
updated examples
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
/*
|
// @ts-ignore somehow causes types:build issues on app
|
||||||
// somehow causes types:build issues on app
|
|
||||||
|
|
||||||
import type { CreateAppConfig } from "bknd";
|
import type { CreateAppConfig } from "bknd";
|
||||||
|
// @ts-ignore somehow causes types:build issues on app
|
||||||
import { serve } from "bknd/adapter/bun";
|
import { serve } from "bknd/adapter/bun";
|
||||||
|
|
||||||
const root = "../../node_modules/bknd/dist";
|
// this is optional, if omitted, it uses an in-memory database
|
||||||
const config = {
|
const config = {
|
||||||
connection: {
|
connection: {
|
||||||
type: "libsql",
|
type: "libsql",
|
||||||
@@ -16,8 +15,12 @@ const config = {
|
|||||||
|
|
||||||
Bun.serve({
|
Bun.serve({
|
||||||
port: 1337,
|
port: 1337,
|
||||||
fetch: serve(config, root)
|
fetch: serve(
|
||||||
|
config,
|
||||||
|
// this is only required to run inside the same workspace
|
||||||
|
// leave blank if you're running this from a different project
|
||||||
|
"../../node_modules/bknd/dist"
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Server running at http://localhost:1337");
|
console.log("Server running at http://localhost:1337");
|
||||||
s*/
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"lib": ["ESNext", "DOM"],
|
"lib": ["ESNext", "DOM"],
|
||||||
"target": "ESNext",
|
"target": "ES2022",
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"jsx": "react-jsx",
|
"jsx": "react-jsx",
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
|
|||||||
@@ -8,15 +8,13 @@ export default serve(
|
|||||||
connection: {
|
connection: {
|
||||||
type: "libsql",
|
type: "libsql",
|
||||||
config: {
|
config: {
|
||||||
url: env.DB_URL,
|
url: "http://localhost:8080"
|
||||||
authToken: env.DB_TOKEN
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
onBuilt: async (app) => {
|
onBuilt: async (app) => {
|
||||||
app.modules.server.get("/", (c) => c.json({ hello: "world" }));
|
app.modules.server.get("/hello", (c) => c.json({ hello: "world" }));
|
||||||
},
|
}
|
||||||
setAdminHtml: true
|
|
||||||
},
|
},
|
||||||
manifest
|
manifest
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
|
"db": "turso dev --db-file test.db",
|
||||||
|
"db:check": "sqlite3 test.db \"PRAGMA wal_checkpoint(FULL);\"",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "next lint"
|
"lint": "next lint"
|
||||||
|
|||||||
@@ -9,51 +9,7 @@ export default serve({
|
|||||||
connection: {
|
connection: {
|
||||||
type: "libsql",
|
type: "libsql",
|
||||||
config: {
|
config: {
|
||||||
url: process.env.DB_URL!,
|
url: "http://localhost:8080"
|
||||||
authToken: process.env.DB_AUTH_TOKEN!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}); /*
|
|
||||||
let app: App;
|
|
||||||
|
|
||||||
async function getApp() {
|
|
||||||
if (!app) {
|
|
||||||
app = App.create({
|
|
||||||
connection: {
|
|
||||||
type: "libsql",
|
|
||||||
config: {
|
|
||||||
url: process.env.DB_URL!,
|
|
||||||
authToken: process.env.DB_AUTH_TOKEN!
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await app.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
return app;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getCleanRequest(req: Request) {
|
|
||||||
// clean search params from "route" attribute
|
|
||||||
const url = new URL(req.url);
|
|
||||||
url.searchParams.delete("route");
|
|
||||||
return new Request(url.toString(), {
|
|
||||||
method: req.method,
|
|
||||||
headers: req.headers,
|
|
||||||
body: req.body
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export default async (req: Request, requestContext: any) => {
|
|
||||||
//console.log("here");
|
|
||||||
if (!app) {
|
|
||||||
app = await getApp();
|
|
||||||
}
|
|
||||||
//const app = await getApp();
|
|
||||||
const request = getCleanRequest(req);
|
|
||||||
//console.log("url", req.url);
|
|
||||||
//console.log("req", req);
|
|
||||||
return app.fetch(request, process.env);
|
|
||||||
};
|
|
||||||
//export default handle(app.server.getInstance())
|
|
||||||
*/
|
|
||||||
|
|||||||
BIN
examples/nextjs/test.db
Normal file
BIN
examples/nextjs/test.db
Normal file
Binary file not shown.
20
examples/node/index.js
Normal file
20
examples/node/index.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { serve } from "bknd/adapter/node";
|
||||||
|
|
||||||
|
// this is optional, if omitted, it uses an in-memory database
|
||||||
|
/** @type {import("bknd").CreateAppConfig} */
|
||||||
|
const config = {
|
||||||
|
connection: {
|
||||||
|
type: "libsql",
|
||||||
|
config: {
|
||||||
|
url: "http://localhost:8080"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
serve(config, {
|
||||||
|
relativeDistPath: "../../node_modules/bknd/dist",
|
||||||
|
port: 1337,
|
||||||
|
listener: ({ port }) => {
|
||||||
|
console.log(`Server is running on http://localhost:${port}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
20
examples/node/package.json
Normal file
20
examples/node/package.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "node",
|
||||||
|
"module": "index.js",
|
||||||
|
"type": "module",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"start": "node index.js",
|
||||||
|
"dev": "tsx --watch index.js"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"bknd": "workspace:*",
|
||||||
|
"@hono/node-server": "^1.13.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"tsx": "^4.19.2"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"typescript": "^5.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@ export default function AdminPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Suspense>
|
<Suspense>
|
||||||
<Admin withProvider />
|
<Admin />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "remix vite:build",
|
"build": "remix vite:build",
|
||||||
"dev": "remix vite:dev",
|
"dev": "remix vite:dev",
|
||||||
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
|
"db": "turso dev --db-file test.db",
|
||||||
|
"db:check": "sqlite3 test.db \"PRAGMA wal_checkpoint(FULL);\"",
|
||||||
"start": "remix-serve ./build/server/index.js",
|
"start": "remix-serve ./build/server/index.js",
|
||||||
"typecheck": "tsc"
|
"typecheck": "tsc"
|
||||||
},
|
},
|
||||||
|
|||||||
BIN
examples/remix/test.db
Normal file
BIN
examples/remix/test.db
Normal file
Binary file not shown.
@@ -7,10 +7,7 @@
|
|||||||
<legend>Params</legend>
|
<legend>Params</legend>
|
||||||
<div>
|
<div>
|
||||||
<label for="entity">Entity:</label>
|
<label for="entity">Entity:</label>
|
||||||
<select id="entity">
|
<select id="entity"></select>
|
||||||
<option value="todos">Todos</option>
|
|
||||||
<option value="notes">Notes</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
@@ -29,6 +26,19 @@
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
fetch("/api/system/config/data")
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(({ config: { entities} }) => {
|
||||||
|
console.log(entities);
|
||||||
|
const entity = document.getElementById('entity');
|
||||||
|
Object.entries(entities).forEach(([name, config]) => {
|
||||||
|
const option = document.createElement('option');
|
||||||
|
option.value = name;
|
||||||
|
option.innerText = config.label ?? name;
|
||||||
|
entity.appendChild(option);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const btn = document.getElementById('btn');
|
const btn = document.getElementById('btn');
|
||||||
const query = document.getElementById('query');
|
const query = document.getElementById('query');
|
||||||
query.onblur = function(e) {
|
query.onblur = function(e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user