mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
cli: try to fallback to env if present
This commit is contained in:
@@ -74,6 +74,7 @@
|
||||
"@vitejs/plugin-react": "^4.3.3",
|
||||
"autoprefixer": "^10.4.20",
|
||||
"clsx": "^2.1.1",
|
||||
"dotenv": "^16.4.7",
|
||||
"esbuild-postcss": "^0.0.4",
|
||||
"jotai": "^2.10.1",
|
||||
"kysely-d1": "^0.3.0",
|
||||
|
||||
@@ -76,3 +76,9 @@ export async function getConfigPath(filePath?: string) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
export function getConnectionCredentialsFromEnv() {
|
||||
const dbUrl = process.env.DB_URL;
|
||||
const dbToken = process.env.DB_TOKEN;
|
||||
return dbUrl ? { url: dbUrl, authToken: dbToken } : undefined;
|
||||
}
|
||||
|
||||
@@ -4,15 +4,18 @@ import { StorageLocalAdapter } from "adapter/node";
|
||||
import type { CliBkndConfig, CliCommand } from "cli/types";
|
||||
import { Option } from "commander";
|
||||
import { config } from "core";
|
||||
import dotenv from "dotenv";
|
||||
import { registries } from "modules/registries";
|
||||
import {
|
||||
PLATFORMS,
|
||||
type Platform,
|
||||
attachServeStatic,
|
||||
getConfigPath,
|
||||
getConnectionCredentialsFromEnv,
|
||||
startServer
|
||||
} from "./platform";
|
||||
|
||||
dotenv.config();
|
||||
const isBun = typeof Bun !== "undefined";
|
||||
|
||||
export const run: CliCommand = (program) => {
|
||||
@@ -101,16 +104,26 @@ async function action(options: {
|
||||
}) {
|
||||
const configFilePath = await getConfigPath(options.config);
|
||||
|
||||
let app: App;
|
||||
if (options.dbUrl || !configFilePath) {
|
||||
let app: App | undefined = undefined;
|
||||
if (options.dbUrl) {
|
||||
const connection = options.dbUrl
|
||||
? { url: options.dbUrl, authToken: options.dbToken }
|
||||
: undefined;
|
||||
app = await makeApp({ connection, server: { platform: options.server } });
|
||||
} else {
|
||||
console.log("Using config from:", configFilePath);
|
||||
} else if (configFilePath) {
|
||||
console.log("[INFO] Using config from:", configFilePath);
|
||||
const config = (await import(configFilePath).then((m) => m.default)) as CliBkndConfig;
|
||||
app = await makeConfigApp(config, options.server);
|
||||
} else {
|
||||
const credentials = getConnectionCredentialsFromEnv();
|
||||
if (credentials) {
|
||||
console.log("[INFO] Using connection from environment");
|
||||
app = await makeConfigApp({ app: { connection: credentials } }, options.server);
|
||||
}
|
||||
}
|
||||
|
||||
if (!app) {
|
||||
app = await makeApp({ server: { platform: options.server } });
|
||||
}
|
||||
|
||||
await startServer(options.server, app, { port: options.port });
|
||||
|
||||
@@ -107,7 +107,6 @@ export class SqliteIntrospector implements DatabaseIntrospector, ConnectionIntro
|
||||
}
|
||||
|
||||
const tables = await query.execute();
|
||||
console.log("tables", tables);
|
||||
return Promise.all(tables.map(({ name }) => this.#getTableMetadata(name)));
|
||||
}
|
||||
|
||||
@@ -119,7 +118,6 @@ export class SqliteIntrospector implements DatabaseIntrospector, ConnectionIntro
|
||||
|
||||
async #getTableMetadata(table: string): Promise<TableMetadata> {
|
||||
const db = this.#db;
|
||||
console.log("get table metadata", table);
|
||||
|
||||
// Get the SQL that was used to create the table.
|
||||
const tableDefinition = await db
|
||||
|
||||
Reference in New Issue
Block a user