mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
fixing sqlite imports, clean up bun and cf examples
This commit is contained in:
@@ -233,7 +233,7 @@ function baseConfig(adapter: string, overrides: Partial<tsup.Options> = {}): tsu
|
|||||||
},
|
},
|
||||||
external: [
|
external: [
|
||||||
/^cloudflare*/,
|
/^cloudflare*/,
|
||||||
/^@?(hono|libsql).*?/,
|
/^@?(hono).*?/,
|
||||||
/^(bknd|react|next|node).*?/,
|
/^(bknd|react|next|node).*?/,
|
||||||
/.*\.(html)$/,
|
/.*\.(html)$/,
|
||||||
...external,
|
...external,
|
||||||
@@ -260,11 +260,7 @@ async function buildAdapters() {
|
|||||||
);
|
);
|
||||||
await tsup.build(baseConfig("astro"));
|
await tsup.build(baseConfig("astro"));
|
||||||
await tsup.build(baseConfig("aws"));
|
await tsup.build(baseConfig("aws"));
|
||||||
await tsup.build(
|
await tsup.build(baseConfig("cloudflare"));
|
||||||
baseConfig("cloudflare", {
|
|
||||||
external: [/^kysely/],
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
await tsup.build({
|
await tsup.build({
|
||||||
...baseConfig("vite"),
|
...baseConfig("vite"),
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"bin": "./dist/cli/index.js",
|
"bin": "./dist/cli/index.js",
|
||||||
"version": "0.15.0-rc.3",
|
"version": "0.15.0-rc.5",
|
||||||
"description": "Lightweight Firebase/Supabase alternative built to run anywhere — incl. Next.js, React Router, Astro, Cloudflare, Bun, Node, AWS Lambda & more.",
|
"description": "Lightweight Firebase/Supabase alternative built to run anywhere — incl. Next.js, React Router, Astro, Cloudflare, Bun, Node, AWS Lambda & more.",
|
||||||
"homepage": "https://bknd.io",
|
"homepage": "https://bknd.io",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import { Database } from "bun:sqlite";
|
import { Database } from "bun:sqlite";
|
||||||
import {
|
import { genericSqlite, type GenericSqliteConnection } from "bknd/data";
|
||||||
genericSqlite,
|
|
||||||
type GenericSqliteConnection,
|
|
||||||
} from "data/connection/sqlite/GenericSqliteConnection";
|
|
||||||
|
|
||||||
export type BunSqliteConnection = GenericSqliteConnection<Database>;
|
export type BunSqliteConnection = GenericSqliteConnection<Database>;
|
||||||
export type BunSqliteConnectionConfig = {
|
export type BunSqliteConnectionConfig = {
|
||||||
|
|||||||
@@ -128,14 +128,14 @@ export function makeConfig<Env extends CloudflareEnv = CloudflareEnv>(
|
|||||||
|
|
||||||
// if db is given in bindings, use it
|
// if db is given in bindings, use it
|
||||||
if (bindings?.db) {
|
if (bindings?.db) {
|
||||||
$console.log("Using database from bindings");
|
$console.debug("Using database from bindings");
|
||||||
db = bindings.db;
|
db = bindings.db;
|
||||||
|
|
||||||
// scan for D1Database in args
|
// scan for D1Database in args
|
||||||
} else {
|
} else {
|
||||||
const binding = getBinding(args.env, "D1Database");
|
const binding = getBinding(args.env, "D1Database");
|
||||||
if (binding) {
|
if (binding) {
|
||||||
$console.log(`Using database from env "${binding.key}"`);
|
$console.debug(`Using database from env "${binding.key}"`);
|
||||||
db = binding.value;
|
db = binding.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
/// <reference types="@cloudflare/workers-types" />
|
/// <reference types="@cloudflare/workers-types" />
|
||||||
|
|
||||||
import {
|
import { genericSqlite, type GenericSqliteConnection } from "bknd/data";
|
||||||
genericSqlite,
|
|
||||||
type GenericSqliteConnection,
|
|
||||||
} from "data/connection/sqlite/GenericSqliteConnection";
|
|
||||||
import type { QueryResult } from "kysely";
|
import type { QueryResult } from "kysely";
|
||||||
|
|
||||||
export type D1SqliteConnection = GenericSqliteConnection<D1Database>;
|
export type D1SqliteConnection = GenericSqliteConnection<D1Database>;
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
/// <reference types="@cloudflare/workers-types" />
|
/// <reference types="@cloudflare/workers-types" />
|
||||||
|
|
||||||
import {
|
import { genericSqlite, type GenericSqliteConnection } from "bknd/data";
|
||||||
genericSqlite,
|
|
||||||
type GenericSqliteConnection,
|
|
||||||
} from "data/connection/sqlite/GenericSqliteConnection";
|
|
||||||
import type { QueryResult } from "kysely";
|
import type { QueryResult } from "kysely";
|
||||||
|
|
||||||
export type D1SqliteConnection = GenericSqliteConnection<D1Database>;
|
export type D1SqliteConnection = GenericSqliteConnection<D1Database>;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { genericSqlite } from "data/connection/sqlite/GenericSqliteConnection";
|
import { genericSqlite } from "bknd/data";
|
||||||
import { DatabaseSync } from "node:sqlite";
|
import { DatabaseSync } from "node:sqlite";
|
||||||
|
|
||||||
export type NodeSqliteConnectionConfig = {
|
export type NodeSqliteConnectionConfig = {
|
||||||
|
|||||||
@@ -29,30 +29,8 @@ export const cloudflare = {
|
|||||||
{ dir: ctx.dir },
|
{ dir: ctx.dir },
|
||||||
);
|
);
|
||||||
|
|
||||||
const db = ctx.skip
|
|
||||||
? "d1"
|
|
||||||
: await $p.select({
|
|
||||||
message: "What database do you want to use?",
|
|
||||||
options: [
|
|
||||||
{ label: "Cloudflare D1", value: "d1" },
|
|
||||||
{ label: "LibSQL", value: "libsql" },
|
|
||||||
],
|
|
||||||
});
|
|
||||||
if ($p.isCancel(db)) {
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch (db) {
|
await createD1(ctx);
|
||||||
case "d1":
|
|
||||||
await createD1(ctx);
|
|
||||||
break;
|
|
||||||
case "libsql":
|
|
||||||
await createLibsql(ctx);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Error("Invalid database");
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const message = (e as any).message || "An error occurred";
|
const message = (e as any).message || "An error occurred";
|
||||||
$p.log.warn(
|
$p.log.warn(
|
||||||
@@ -60,7 +38,14 @@ export const cloudflare = {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await createR2(ctx);
|
try {
|
||||||
|
await createR2(ctx);
|
||||||
|
} catch (e) {
|
||||||
|
const message = (e as any).message || "An error occurred";
|
||||||
|
$p.log.warn(
|
||||||
|
"Couldn't add R2 bucket. You can add it manually later. Error: " + c.red(message),
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
} as const satisfies Template;
|
} as const satisfies Template;
|
||||||
|
|
||||||
@@ -89,6 +74,21 @@ async function createD1(ctx: TemplateSetupCtx) {
|
|||||||
})(),
|
})(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await overrideJson(
|
||||||
|
WRANGLER_FILE,
|
||||||
|
(json) => ({
|
||||||
|
...json,
|
||||||
|
d1_databases: [
|
||||||
|
{
|
||||||
|
binding: "DB",
|
||||||
|
database_name: name,
|
||||||
|
database_id: "00000000-0000-0000-0000-000000000000",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
{ dir: ctx.dir },
|
||||||
|
);
|
||||||
|
|
||||||
if (!ctx.skip) {
|
if (!ctx.skip) {
|
||||||
exec(`npx wrangler d1 create ${name}`);
|
exec(`npx wrangler d1 create ${name}`);
|
||||||
|
|
||||||
@@ -98,62 +98,6 @@ async function createD1(ctx: TemplateSetupCtx) {
|
|||||||
})(),
|
})(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await overrideJson(
|
|
||||||
WRANGLER_FILE,
|
|
||||||
(json) => ({
|
|
||||||
...json,
|
|
||||||
d1_databases: [
|
|
||||||
{
|
|
||||||
binding: "DB",
|
|
||||||
database_name: name,
|
|
||||||
database_id: uuid(),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
{ dir: ctx.dir },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function createLibsql(ctx: TemplateSetupCtx) {
|
|
||||||
await overrideJson(
|
|
||||||
WRANGLER_FILE,
|
|
||||||
(json) => ({
|
|
||||||
...json,
|
|
||||||
vars: {
|
|
||||||
DB_URL: "http://127.0.0.1:8080",
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
{ dir: ctx.dir },
|
|
||||||
);
|
|
||||||
|
|
||||||
await overridePackageJson(
|
|
||||||
(pkg) => ({
|
|
||||||
...pkg,
|
|
||||||
scripts: {
|
|
||||||
...pkg.scripts,
|
|
||||||
db: "turso dev",
|
|
||||||
dev: "npm run db && wrangler dev",
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
{ dir: ctx.dir },
|
|
||||||
);
|
|
||||||
|
|
||||||
await $p.stream.info(
|
|
||||||
(async function* () {
|
|
||||||
yield* typewriter("Database set to LibSQL");
|
|
||||||
await wait();
|
|
||||||
yield* typewriter(
|
|
||||||
`\nYou can now run ${c.cyan("npm run db")} to start the database and ${c.cyan("npm run dev")} to start the worker.`,
|
|
||||||
c.dim,
|
|
||||||
);
|
|
||||||
await wait();
|
|
||||||
yield* typewriter(
|
|
||||||
`\nAlso make sure you have Turso's CLI installed. Check their docs on how to install at ${c.cyan("https://docs.turso.tech/cli/introduction")}`,
|
|
||||||
c.dim,
|
|
||||||
);
|
|
||||||
})(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createR2(ctx: TemplateSetupCtx) {
|
async function createR2(ctx: TemplateSetupCtx) {
|
||||||
@@ -197,9 +141,11 @@ async function createR2(ctx: TemplateSetupCtx) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx.skip) {
|
await $p.stream.info(
|
||||||
exec(`npx wrangler r2 bucket create ${name}`);
|
(async function* () {
|
||||||
}
|
yield* typewriter("Now running wrangler to create a R2 bucket...");
|
||||||
|
})(),
|
||||||
|
);
|
||||||
|
|
||||||
await overrideJson(
|
await overrideJson(
|
||||||
WRANGLER_FILE,
|
WRANGLER_FILE,
|
||||||
@@ -214,4 +160,8 @@ async function createR2(ctx: TemplateSetupCtx) {
|
|||||||
}),
|
}),
|
||||||
{ dir: ctx.dir },
|
{ dir: ctx.dir },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!ctx.skip) {
|
||||||
|
exec(`npx wrangler r2 bucket create ${name}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
3
examples/.gitignore
vendored
3
examples/.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
*/package-lock.json
|
*/package-lock.json
|
||||||
|
*/bun.lock
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
// @ts-ignore somehow causes types:build issues on app
|
|
||||||
import { type BunBkndConfig, serve } from "bknd/adapter/bun";
|
|
||||||
|
|
||||||
// Actually, all it takes is the following line:
|
|
||||||
// serve();
|
|
||||||
|
|
||||||
// this is optional, if omitted, it uses an in-memory database
|
|
||||||
const config: BunBkndConfig = {
|
|
||||||
adminOptions: {
|
|
||||||
assets_path: "https://cdn.bknd.io/0.9.0-rc.1/",
|
|
||||||
},
|
|
||||||
connection: {
|
|
||||||
url: "file:data.db",
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
serve(config);
|
|
||||||
@@ -8,8 +8,7 @@
|
|||||||
"typegen": "wrangler types"
|
"typegen": "wrangler types"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bknd": "file:../../app",
|
"bknd": "file:../../app"
|
||||||
"kysely-d1": "^0.4.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"typescript": "^5.8.3",
|
"typescript": "^5.8.3",
|
||||||
|
|||||||
Reference in New Issue
Block a user