@batadata/cli 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/db.d.ts +12 -0
- package/dist/commands/db.js +13 -5
- package/package.json +1 -1
package/dist/commands/db.d.ts
CHANGED
|
@@ -38,5 +38,17 @@ export declare function branchSetProtected(ref: string | undefined, wantProtecte
|
|
|
38
38
|
*/
|
|
39
39
|
export declare function branchCheckout(args: string[]): Promise<void>;
|
|
40
40
|
export declare function studio(): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Pull `--branch <ref>` / `--at <ISO-timestamp|LSN>` flags (and their `=` forms)
|
|
43
|
+
* out of the query args and return them plus the remaining args, which join into
|
|
44
|
+
* the SQL string. Keeps `db query` order-independent (flags can sit before or
|
|
45
|
+
* after the SQL) and consistent with how global flags are parsed.
|
|
46
|
+
*/
|
|
47
|
+
export declare function parseQueryFlags(args: string[]): {
|
|
48
|
+
branchId?: string;
|
|
49
|
+
at?: string;
|
|
50
|
+
projectId?: string;
|
|
51
|
+
rest: string[];
|
|
52
|
+
};
|
|
41
53
|
export declare function query(args?: string[]): Promise<void>;
|
|
42
54
|
export declare function handleDb(args: string[]): Promise<void>;
|
package/dist/commands/db.js
CHANGED
|
@@ -499,9 +499,10 @@ export async function studio() {
|
|
|
499
499
|
* the SQL string. Keeps `db query` order-independent (flags can sit before or
|
|
500
500
|
* after the SQL) and consistent with how global flags are parsed.
|
|
501
501
|
*/
|
|
502
|
-
function parseQueryFlags(args) {
|
|
502
|
+
export function parseQueryFlags(args) {
|
|
503
503
|
let branchId;
|
|
504
504
|
let at;
|
|
505
|
+
let projectId;
|
|
505
506
|
const rest = [];
|
|
506
507
|
for (let i = 0; i < args.length; i++) {
|
|
507
508
|
const arg = args[i];
|
|
@@ -517,11 +518,17 @@ function parseQueryFlags(args) {
|
|
|
517
518
|
else if (arg.startsWith("--at=")) {
|
|
518
519
|
at = arg.slice("--at=".length);
|
|
519
520
|
}
|
|
521
|
+
else if (arg === "--project") {
|
|
522
|
+
projectId = args[++i];
|
|
523
|
+
}
|
|
524
|
+
else if (arg.startsWith("--project=")) {
|
|
525
|
+
projectId = arg.slice("--project=".length);
|
|
526
|
+
}
|
|
520
527
|
else {
|
|
521
528
|
rest.push(arg);
|
|
522
529
|
}
|
|
523
530
|
}
|
|
524
|
-
return { branchId, at, rest };
|
|
531
|
+
return { branchId, at, projectId, rest };
|
|
525
532
|
}
|
|
526
533
|
/**
|
|
527
534
|
* Resolve the branch a query should target: an explicit `--branch <id-or-name>`
|
|
@@ -621,7 +628,7 @@ async function runTimeTravelQuery(opts) {
|
|
|
621
628
|
}
|
|
622
629
|
export async function query(args = []) {
|
|
623
630
|
const jsonMode = isJsonMode();
|
|
624
|
-
const { branchId: branchFlag, at, rest } = parseQueryFlags(args);
|
|
631
|
+
const { branchId: branchFlag, at, projectId: projectFlag, rest } = parseQueryFlags(args);
|
|
625
632
|
// Branch precedence: an explicit --branch wins, else the branch pinned by
|
|
626
633
|
// `bata db branch checkout` in .batadata/project.json, else the primary.
|
|
627
634
|
const branchId = resolveBranchId(branchFlag).branchId;
|
|
@@ -631,9 +638,10 @@ export async function query(args = []) {
|
|
|
631
638
|
}
|
|
632
639
|
const token = requireToken();
|
|
633
640
|
const config = loadConfig();
|
|
634
|
-
|
|
641
|
+
// Project precedence: --project flag > .batadata link > config default.
|
|
642
|
+
const projectId = resolveProjectId(projectFlag).projectId;
|
|
635
643
|
if (!projectId) {
|
|
636
|
-
emitError("NO_PROJECT", "No
|
|
644
|
+
emitError("NO_PROJECT", "No project for db query.", "Pass --project <id>, or run `bata link <project>` to set a default.");
|
|
637
645
|
}
|
|
638
646
|
// `--at` is a time-travel query: fork a hidden ephemeral branch AS OF the point
|
|
639
647
|
// and run the SQL there. Classify the point up front so a bad --at fails fast.
|