mirror of
https://github.com/withastro/astro.git
synced 2025-02-03 22:29:08 -05:00
add simple db shell
This commit is contained in:
parent
2c897aea2a
commit
d0102e6725
2 changed files with 24 additions and 0 deletions
20
packages/db/src/cli/commands/shell/index.ts
Normal file
20
packages/db/src/cli/commands/shell/index.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
import type { AstroConfig } from 'astro';
|
||||
import { sql } from 'drizzle-orm';
|
||||
import type { Arguments } from 'yargs-parser';
|
||||
import { appTokenError } from '../../../errors.js';
|
||||
import { createRemoteDatabaseClient, getAstroStudioEnv } from '../../../utils.js';
|
||||
|
||||
export async function cmd({ config, flags }: { config: AstroConfig; flags: Arguments }) {
|
||||
const query = flags.query;
|
||||
const appToken = flags.token ?? getAstroStudioEnv().ASTRO_STUDIO_APP_TOKEN;
|
||||
if (!appToken) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(appTokenError);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const db = createRemoteDatabaseClient(appToken);
|
||||
// Temporary: create the migration table just in case it doesn't exist
|
||||
const result = await db.run(sql.raw(query));
|
||||
console.log(result);
|
||||
}
|
|
@ -5,6 +5,10 @@ export async function cli({ flags, config }: { flags: Arguments; config: AstroCo
|
|||
const command = flags._[3] as string;
|
||||
|
||||
switch (command) {
|
||||
case 'shell': {
|
||||
const { cmd: shellCommand } = await import('./commands/shell/index.js');
|
||||
return await shellCommand({ config, flags });
|
||||
}
|
||||
case 'sync': {
|
||||
const { cmd: syncCommand } = await import('./commands/sync/index.js');
|
||||
return await syncCommand({ config, flags });
|
||||
|
|
Loading…
Add table
Reference in a new issue