Comparing version 0.0.25 to 0.0.26
@@ -41,4 +41,9 @@ "use strict"; | ||
.argument('[id]', "the id of the primary key in the first table in the path") | ||
.option('-p, --plan', "show the plan instead of executing", false) | ||
.option(' --plan', "show the plan instead of executing", false) | ||
.option('-s, --sql', "show the sql instead of executing", false) | ||
.option('--fullSql', "normally the show sql doesn't include limits. This shows them", false) | ||
.option('-c, --count', "returns the count of the items in the table", false) | ||
.option('-d, --distinct', "only return distinct values", false) | ||
.option('--page <page> ', "which page of the results should be returned") | ||
.option("--pageSize <pageSize>", "Changes the page of the returned results", parseInt, 15) | ||
.option('-t, --trace', "trace the results", false) | ||
@@ -52,11 +57,18 @@ .option('-j, --json', "Sql output as json instead of columns", false) | ||
.action((path, id, options) => __awaiter(this, void 0, void 0, function* () { | ||
const where = options.where ? options.where : []; | ||
let pathSpec = (0, tables_1.makePathSpec)(path, id, options, where); | ||
const env = config.environments.dev; | ||
if (options.trace) { | ||
const pps = yield (0, path_1.tracePlan)(env, config.tables, pathSpec, options); | ||
if (!env) | ||
throw new Error('Need to have a dev environment'); | ||
const dialect = (0, environments_1.sqlDialect)(env.type); | ||
const page = options.page ? parseInt(options.page) : 1; | ||
const fullOptions = Object.assign(Object.assign({}, options), { limitBy: dialect.limitFn, page }); | ||
if (page < 1) | ||
throw new Error("Page must be greater than 0"); | ||
const where = fullOptions.where ? fullOptions.where : []; | ||
let pathSpec = (0, tables_1.makePathSpec)(path, id, fullOptions, where); | ||
if (fullOptions.trace) { | ||
const pps = yield (0, path_1.tracePlan)(env, config.tables, pathSpec, fullOptions); | ||
pps.forEach(line => console.log(line)); | ||
return; | ||
} | ||
const errorsOrresult = yield (0, path_1.processPathString)(env, config.tables, pathSpec, options); | ||
const errorsOrresult = yield (0, path_1.processPathString)(env, config.tables, pathSpec, fullOptions); | ||
if ((0, utils_1.hasErrors)(errorsOrresult)) { | ||
@@ -66,3 +78,3 @@ (0, utils_1.reportErrors)(errorsOrresult); | ||
} | ||
(0, path_1.prettyPrintPP)(options, errorsOrresult).forEach(line => console.log(line)); | ||
(0, path_1.prettyPrintPP)(fullOptions, errorsOrresult).forEach(line => console.log(line)); | ||
})); | ||
@@ -69,0 +81,0 @@ (0, tables_1.findQueryParams)(config.tables).forEach(param => program.option('--' + param.name + " <" + param.name + ">", param.description)); |
import { ErrorsAnd, NameAnd } from "@db-auto/utils"; | ||
import { CleanTable, PathSpec, SelectData } from "@db-auto/tables"; | ||
import { CleanTable, PathSpec, SelectData, SqlOptions } from "@db-auto/tables"; | ||
import { Environment } from "@db-auto/environments"; | ||
@@ -22,5 +22,6 @@ import { DalResult, DalResultDisplayOptions } from "@db-auto/dal"; | ||
type PP = SelectDataPP | LinksPP | SqlPP | ResPP; | ||
interface ProcessPathOptions extends DalResultDisplayOptions { | ||
interface ProcessPathOptions extends DalResultDisplayOptions, SqlOptions { | ||
plan?: boolean; | ||
sql?: boolean; | ||
fullSql?: boolean; | ||
} | ||
@@ -27,0 +28,0 @@ export declare function processPathString(env: Environment, tables: NameAnd<CleanTable>, pathSpec: PathSpec, options: ProcessPathOptions): Promise<ErrorsAnd<PP>>; |
@@ -15,3 +15,3 @@ "use strict"; | ||
const tables_1 = require("@db-auto/tables"); | ||
const postgres_1 = require("@db-auto/postgres"); | ||
const environments_1 = require("@db-auto/environments"); | ||
const dal_1 = require("@db-auto/dal"); | ||
@@ -47,9 +47,10 @@ function findLinks(tables, path) { | ||
const data = (0, tables_1.selectData)("all")(plan); | ||
const { plan: showPlan, sql: showSql } = options; | ||
const { plan: showPlan, sql: showSql, fullSql } = options; | ||
if (showPlan) | ||
return { type: 'selectData', data }; | ||
const sql = (0, tables_1.sqlFor)((0, tables_1.mergeSelectData)(data)); | ||
if (showSql) | ||
const optionsModifiedForLimits = showSql && !fullSql ? Object.assign(Object.assign({}, options), { limitBy: undefined }) : options; | ||
const sql = (0, tables_1.sqlFor)(optionsModifiedForLimits)((0, tables_1.mergeSelectData)(data)); | ||
if (showSql || fullSql) | ||
return ({ type: 'sql', sql }); | ||
const dal = (0, postgres_1.postgresDal)(env); | ||
const dal = (0, environments_1.dalFor)(env); | ||
try { | ||
@@ -56,0 +57,0 @@ const result = { type: 'res', res: yield dal.query(sql.join(' ')) }; |
@@ -112,3 +112,3 @@ "use strict"; | ||
const actual = yield (0, path_1.processPathString)(dev, tables_1.clean, pathSpec, { sql: true }); | ||
const sql = (0, utils_1.mapErrors)((0, tables_1.buildPlan)(tables_1.clean, pathSpec), plan => (0, tables_1.sqlFor)((0, tables_1.mergeSelectData)((0, tables_1.selectData)("all")(plan)))); | ||
const sql = (0, utils_1.mapErrors)((0, tables_1.buildPlan)(tables_1.clean, pathSpec), plan => (0, tables_1.sqlFor)({})((0, tables_1.mergeSelectData)((0, tables_1.selectData)("all")(plan)))); | ||
const expected = { type: 'sql', sql }; | ||
@@ -115,0 +115,0 @@ return { actual, expected }; |
{ | ||
"name": "db-auto", | ||
"description": "", | ||
"version": "0.0.25", | ||
"version": "0.0.26", | ||
"main": "dist/index", | ||
@@ -24,10 +24,10 @@ "types": "dist/index", | ||
"commander": "^10.0.0", | ||
"@db-auto/oracle": "0.0.25", | ||
"@db-auto/mysql": "0.0.25", | ||
"@db-auto/postgres": "0.0.25", | ||
"@db-auto/tables": "0.0.25", | ||
"@db-auto/utils": "0.0.25", | ||
"@db-auto/files": "0.0.25", | ||
"@db-auto/mocks": "0.0.25", | ||
"@db-auto/environments": "0.0.25" | ||
"@db-auto/oracle": "0.0.26", | ||
"@db-auto/mysql": "0.0.26", | ||
"@db-auto/postgres": "0.0.26", | ||
"@db-auto/tables": "0.0.26", | ||
"@db-auto/utils": "0.0.26", | ||
"@db-auto/files": "0.0.26", | ||
"@db-auto/mocks": "0.0.26", | ||
"@db-auto/environments": "0.0.26" | ||
}, | ||
@@ -34,0 +34,0 @@ "devDependencies": { |
42663
656
+ Added@db-auto/dal@0.0.26(transitive)
+ Added@db-auto/environments@0.0.26(transitive)
+ Added@db-auto/files@0.0.26(transitive)
+ Added@db-auto/mocks@0.0.26(transitive)
+ Added@db-auto/mysql@0.0.26(transitive)
+ Added@db-auto/oracle@0.0.26(transitive)
+ Added@db-auto/postgres@0.0.26(transitive)
+ Added@db-auto/tables@0.0.26(transitive)
+ Added@db-auto/utils@0.0.26(transitive)
- Removed@db-auto/dal@0.0.25(transitive)
- Removed@db-auto/environments@0.0.25(transitive)
- Removed@db-auto/files@0.0.25(transitive)
- Removed@db-auto/mocks@0.0.25(transitive)
- Removed@db-auto/mysql@0.0.25(transitive)
- Removed@db-auto/oracle@0.0.25(transitive)
- Removed@db-auto/postgres@0.0.25(transitive)
- Removed@db-auto/tables@0.0.25(transitive)
- Removed@db-auto/utils@0.0.25(transitive)
Updated@db-auto/environments@0.0.26
Updated@db-auto/files@0.0.26
Updated@db-auto/mocks@0.0.26
Updated@db-auto/mysql@0.0.26
Updated@db-auto/oracle@0.0.26
Updated@db-auto/postgres@0.0.26
Updated@db-auto/tables@0.0.26
Updated@db-auto/utils@0.0.26