Comparing version 0.0.27 to 0.0.28
@@ -6,3 +6,4 @@ #!/usr/bin/env node | ||
const cli_1 = require("./src/cli"); | ||
const config = (0, cli_1.makeConfig)(process.cwd(), process.env); | ||
let cwd = process.cwd(); | ||
const config = (0, cli_1.makeConfig)(cwd, process.env); | ||
if ((0, utils_1.hasErrors)(config)) { | ||
@@ -12,3 +13,3 @@ (0, utils_1.reportErrors)(config); | ||
} | ||
const program = (0, cli_1.makeProgram)(config, (0, cli_1.findVersion)()); | ||
const program = (0, cli_1.makeProgram)(cwd, config, (0, cli_1.findVersion)()); | ||
(0, cli_1.processProgram)(program, process.argv); |
@@ -6,3 +6,3 @@ import { Command } from "commander"; | ||
export declare function findVersion(): any; | ||
export declare function makeProgram(config: CleanConfig, version: string): Command; | ||
export declare function makeProgram(cwd: string, config: CleanConfig, version: string): Command; | ||
export declare function processProgram(program: Command, args: string[]): void; |
@@ -35,3 +35,3 @@ "use strict"; | ||
exports.findVersion = findVersion; | ||
function makeProgram(config, version) { | ||
function makeProgram(cwd, config, version) { | ||
let program = new commander_1.Command() | ||
@@ -44,2 +44,3 @@ .name('db-auto') | ||
.option('-s, --sql', "show the sql instead of executing", false) | ||
.option('-e, --env <env>', "override the default environment. Use 'db-auto envs' to see a list of names") | ||
.option('--fullSql', "normally the show sql doesn't include limits. This shows them", false) | ||
@@ -58,5 +59,9 @@ .option('-c, --count', "returns the count of the items in the table", false) | ||
.action((path, id, options) => __awaiter(this, void 0, void 0, function* () { | ||
const env = config.environments.dev; | ||
if (!env) | ||
throw new Error('Need to have a dev environment'); | ||
//TODO move sql dialect here.. | ||
const envAndNameOrErrors = (0, environments_1.currentEnvironment)(cwd, config.environments, options.env); | ||
if ((0, utils_1.hasErrors)(envAndNameOrErrors)) { | ||
(0, utils_1.reportErrors)(envAndNameOrErrors); | ||
return; | ||
} | ||
const { env, envName } = envAndNameOrErrors; | ||
const dialect = (0, environments_1.sqlDialect)(env.type); | ||
@@ -70,7 +75,7 @@ const page = options.page ? parseInt(options.page) : 1; | ||
if (fullOptions.trace) { | ||
const pps = yield (0, path_1.tracePlan)(env, config.tables, pathSpec, fullOptions); | ||
const pps = yield (0, path_1.tracePlan)(envAndNameOrErrors, config.tables, pathSpec, fullOptions); | ||
pps.forEach(line => console.log(line)); | ||
return; | ||
} | ||
const errorsOrresult = yield (0, path_1.processPathString)(env, config.tables, pathSpec, fullOptions); | ||
const errorsOrresult = yield (0, path_1.processPathString)(envAndNameOrErrors, config.tables, pathSpec, fullOptions); | ||
if ((0, utils_1.hasErrors)(errorsOrresult)) { | ||
@@ -80,3 +85,3 @@ (0, utils_1.reportErrors)(errorsOrresult); | ||
} | ||
(0, path_1.prettyPrintPP)(fullOptions, errorsOrresult).forEach(line => console.log(line)); | ||
(0, path_1.prettyPrintPP)(fullOptions, true, errorsOrresult).forEach(line => console.log(line)); | ||
})); | ||
@@ -94,4 +99,20 @@ (0, tables_1.findQueryParams)(config.tables).forEach(param => program.option('--' + param.name + " <" + param.name + ">", param.description)); | ||
.action((command, options) => { | ||
const envAndNameOrErrors = (0, environments_1.currentEnvironment)(cwd, config.environments, options.env); | ||
if ((0, utils_1.hasErrors)(envAndNameOrErrors)) { | ||
(0, utils_1.reportErrors)(envAndNameOrErrors); | ||
return; | ||
} | ||
console.log("Current environment is " + envAndNameOrErrors.envName); | ||
(0, environments_1.prettyPrintEnvironments)(config.environments).forEach(line => console.log(line)); | ||
}); | ||
const env = program.command('env') | ||
.arguments('<env>') | ||
.action((env, command, options) => { | ||
const check = config.environments[env]; | ||
if (!check) { | ||
console.log(`Environment ${env} is not defined`); | ||
process.exit(1); | ||
} | ||
(0, environments_1.saveEnvName)(cwd, env); | ||
}); | ||
const tables = program.command('tables') | ||
@@ -98,0 +119,0 @@ .action((command, options) => { |
import { ErrorsAnd, NameAnd } from "@db-auto/utils"; | ||
import { CleanTable, PathSpec, SelectData, SqlOptions } from "@db-auto/tables"; | ||
import { Environment } from "@db-auto/environments"; | ||
import { EnvAndName } from "@db-auto/environments"; | ||
import { DalResult, DalResultDisplayOptions } from "@db-auto/dal"; | ||
@@ -16,2 +16,3 @@ export interface SelectDataPP { | ||
sql: string[]; | ||
envName: string; | ||
} | ||
@@ -28,6 +29,6 @@ export interface ResPP { | ||
} | ||
export declare function processPathString(env: Environment, tables: NameAnd<CleanTable>, pathSpec: PathSpec, options: ProcessPathOptions): Promise<ErrorsAnd<PP>>; | ||
export declare function prettyPrintPP(options: DalResultDisplayOptions, pp: PP): string[]; | ||
export declare function processPathString(envAndName: EnvAndName, tables: NameAnd<CleanTable>, pathSpec: PathSpec, options: ProcessPathOptions): Promise<ErrorsAnd<PP>>; | ||
export declare function prettyPrintPP(options: DalResultDisplayOptions, showSql: boolean, pp: PP): string[]; | ||
export declare function makeTracePlanSpecs(pathSpec: PathSpec): PathSpec[]; | ||
export declare function tracePlan(env: Environment, tables: NameAnd<CleanTable>, pathSpec: PathSpec, options: ProcessPathOptions): Promise<string[]>; | ||
export declare function tracePlan(env: EnvAndName, tables: NameAnd<CleanTable>, pathSpec: PathSpec, options: ProcessPathOptions): Promise<string[]>; | ||
export {}; |
@@ -34,5 +34,6 @@ "use strict"; | ||
} | ||
function processPathString(env, tables, pathSpec, options) { | ||
function processPathString(envAndName, tables, pathSpec, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const path = pathSpec.path; | ||
const { env, envName } = envAndName; | ||
if (path.length === 0) | ||
@@ -53,3 +54,3 @@ return ['Path must have at least one part']; | ||
if (showSql || fullSql) | ||
return ({ type: 'sql', sql }); | ||
return ({ type: 'sql', sql, envName }); | ||
const dal = (0, environments_1.dalFor)(env); | ||
@@ -66,3 +67,3 @@ try { | ||
exports.processPathString = processPathString; | ||
function prettyPrintPP(options, pp) { | ||
function prettyPrintPP(options, showSql, pp) { | ||
if (pp.type === 'links') | ||
@@ -72,4 +73,6 @@ return ["Links:", ' ' + pp.links.join(', ')]; | ||
return [JSON.stringify(pp.data, null, 2)]; | ||
if (pp.type === 'sql') | ||
return pp.sql; | ||
if (pp.type === 'sql') { | ||
let env = showSql ? [`Environment: ${pp.envName}`] : []; | ||
return [...env, ...pp.sql]; | ||
} | ||
if (pp.type === 'res') | ||
@@ -99,5 +102,5 @@ return (0, dal_1.prettyPrintDalResult)(options, pp.res); | ||
} | ||
return (0, utils_1.flatMap)(result, (pp, i) => [`${specs[i].path.join('.')}`, ...prettyPrintPP(options, pp), '']); | ||
return [`Environment: ${env.envName}`, ...(0, utils_1.flatMap)(result, (pp, i) => [`${specs[i].path.join('.')}`, ...prettyPrintPP(options, false, pp), ''])]; | ||
}); | ||
} | ||
exports.tracePlan = tracePlan; |
@@ -16,7 +16,7 @@ "use strict"; | ||
const environments_1 = require("@db-auto/environments"); | ||
const dev = environments_1.cleanEnv.dev; | ||
const envAndName = { env: environments_1.cleanEnv.dev, envName: 'dev' }; | ||
describe('processPath', () => { | ||
describe('notfounds', () => { | ||
it('should handle notfound', () => __awaiter(void 0, void 0, void 0, function* () { | ||
expect(yield (0, path_1.processPathString)(dev, tables_1.clean, (0, tables_1.makePathSpec)('notfound'), {})).toEqual([ | ||
expect(yield (0, path_1.processPathString)(envAndName, tables_1.clean, (0, tables_1.makePathSpec)('notfound'), {})).toEqual([ | ||
"Cannot find table notfound in tables. Available tables are: driver,driver_aud,mission,mission_aud" | ||
@@ -26,3 +26,3 @@ ]); | ||
it('should handle notfound.?', () => __awaiter(void 0, void 0, void 0, function* () { | ||
expect(yield (0, path_1.processPathString)(dev, tables_1.clean, (0, tables_1.makePathSpec)('notfound.?'), {})).toEqual([ | ||
expect(yield (0, path_1.processPathString)(envAndName, tables_1.clean, (0, tables_1.makePathSpec)('notfound.?'), {})).toEqual([ | ||
"Cannot find table notfound in tables. Available tables are: driver,driver_aud,mission,mission_aud" | ||
@@ -32,3 +32,3 @@ ]); | ||
it('should handle driver.notfound.', () => __awaiter(void 0, void 0, void 0, function* () { | ||
expect(yield (0, path_1.processPathString)(dev, tables_1.clean, (0, tables_1.makePathSpec)('driver.notfound'), {})).toEqual([ | ||
expect(yield (0, path_1.processPathString)(envAndName, tables_1.clean, (0, tables_1.makePathSpec)('driver.notfound'), {})).toEqual([ | ||
"Cannot find link notfound in table DriverTable for path [driver]. Available links are: audit,mission" | ||
@@ -38,3 +38,3 @@ ]); | ||
it('should handle driver.notfound.?', () => __awaiter(void 0, void 0, void 0, function* () { | ||
expect(yield (0, path_1.processPathString)(dev, tables_1.clean, (0, tables_1.makePathSpec)('driver.notfound.?'), {})).toEqual([ | ||
expect(yield (0, path_1.processPathString)(envAndName, tables_1.clean, (0, tables_1.makePathSpec)('driver.notfound.?'), {})).toEqual([ | ||
"Cannot find link notfound in table DriverTable for path [driver]. Available links are: audit,mission", | ||
@@ -44,3 +44,3 @@ ]); | ||
it('should handle driver.mission.notfound.?', () => __awaiter(void 0, void 0, void 0, function* () { | ||
expect(yield (0, path_1.processPathString)(dev, tables_1.clean, (0, tables_1.makePathSpec)('driver.mission.notfound.?'), {})).toEqual([ | ||
expect(yield (0, path_1.processPathString)(envAndName, tables_1.clean, (0, tables_1.makePathSpec)('driver.mission.notfound.?'), {})).toEqual([ | ||
"Cannot find link notfound in table mission for path [driver.mission]. Available links are: driver,mission_aud" | ||
@@ -52,3 +52,3 @@ ]); | ||
it('should handle ?', () => __awaiter(void 0, void 0, void 0, function* () { | ||
expect(yield (0, path_1.processPathString)(dev, tables_1.clean, (0, tables_1.makePathSpec)('?'), {})) | ||
expect(yield (0, path_1.processPathString)(envAndName, tables_1.clean, (0, tables_1.makePathSpec)('?'), {})) | ||
.toEqual({ | ||
@@ -60,3 +60,3 @@ "links": ["driver", "driver_aud", "mission", "mission_aud"], | ||
it('should handle d?', () => __awaiter(void 0, void 0, void 0, function* () { | ||
expect(yield (0, path_1.processPathString)(dev, tables_1.clean, (0, tables_1.makePathSpec)('d?'), {})) | ||
expect(yield (0, path_1.processPathString)(envAndName, tables_1.clean, (0, tables_1.makePathSpec)('d?'), {})) | ||
.toEqual({ | ||
@@ -68,3 +68,3 @@ "links": ["driver", "driver_aud"], | ||
it('should handle notin?', () => __awaiter(void 0, void 0, void 0, function* () { | ||
expect(yield (0, path_1.processPathString)(dev, tables_1.clean, (0, tables_1.makePathSpec)('notin?'), {})) | ||
expect(yield (0, path_1.processPathString)(envAndName, tables_1.clean, (0, tables_1.makePathSpec)('notin?'), {})) | ||
.toEqual({ | ||
@@ -76,3 +76,3 @@ "links": [], | ||
it("should handle driver.?", () => __awaiter(void 0, void 0, void 0, function* () { | ||
expect(yield (0, path_1.processPathString)(dev, tables_1.clean, (0, tables_1.makePathSpec)("driver.?"), {})).toEqual({ | ||
expect(yield (0, path_1.processPathString)(envAndName, tables_1.clean, (0, tables_1.makePathSpec)("driver.?"), {})).toEqual({ | ||
"links": ["mission", "audit"], | ||
@@ -83,3 +83,3 @@ "type": "links" | ||
it("should handle driver.m?", () => __awaiter(void 0, void 0, void 0, function* () { | ||
expect(yield (0, path_1.processPathString)(dev, tables_1.clean, (0, tables_1.makePathSpec)("driver.m?"), {})).toEqual({ | ||
expect(yield (0, path_1.processPathString)(envAndName, tables_1.clean, (0, tables_1.makePathSpec)("driver.m?"), {})).toEqual({ | ||
"links": ["mission"], | ||
@@ -90,3 +90,3 @@ "type": "links" | ||
it("should handle driver.notin?", () => __awaiter(void 0, void 0, void 0, function* () { | ||
expect(yield (0, path_1.processPathString)(dev, tables_1.clean, (0, tables_1.makePathSpec)("driver.notin?"), {})).toEqual({ | ||
expect(yield (0, path_1.processPathString)(envAndName, tables_1.clean, (0, tables_1.makePathSpec)("driver.notin?"), {})).toEqual({ | ||
"links": [], | ||
@@ -100,3 +100,3 @@ "type": "links" | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const actual = yield (0, path_1.processPathString)(dev, tables_1.clean, (0, tables_1.makePathSpec)(path), { plan: true }); | ||
const actual = yield (0, path_1.processPathString)(envAndName, tables_1.clean, (0, tables_1.makePathSpec)(path), { plan: true }); | ||
const data = (0, utils_1.mapErrors)((0, tables_1.buildPlan)(tables_1.clean, (0, tables_1.makePathSpec)(path)), (0, tables_1.selectData)("all")); | ||
@@ -123,5 +123,5 @@ const expected = { type: 'selectData', data }; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const actual = yield (0, path_1.processPathString)(dev, tables_1.clean, pathSpec, { sql: true }); | ||
const actual = yield (0, path_1.processPathString)(envAndName, 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 expected = { type: 'sql', sql }; | ||
const expected = { type: 'sql', sql, envName: 'dev' }; | ||
return { actual, expected }; | ||
@@ -128,0 +128,0 @@ }); |
{ | ||
"name": "db-auto", | ||
"description": "", | ||
"version": "0.0.27", | ||
"version": "0.0.28", | ||
"main": "dist/index", | ||
@@ -24,10 +24,10 @@ "types": "dist/index", | ||
"commander": "^10.0.0", | ||
"@db-auto/oracle": "0.0.27", | ||
"@db-auto/mysql": "0.0.27", | ||
"@db-auto/postgres": "0.0.27", | ||
"@db-auto/tables": "0.0.27", | ||
"@db-auto/utils": "0.0.27", | ||
"@db-auto/files": "0.0.27", | ||
"@db-auto/mocks": "0.0.27", | ||
"@db-auto/environments": "0.0.27" | ||
"@db-auto/oracle": "0.0.28", | ||
"@db-auto/mysql": "0.0.28", | ||
"@db-auto/postgres": "0.0.28", | ||
"@db-auto/tables": "0.0.28", | ||
"@db-auto/utils": "0.0.28", | ||
"@db-auto/files": "0.0.28", | ||
"@db-auto/mocks": "0.0.28", | ||
"@db-auto/environments": "0.0.28" | ||
}, | ||
@@ -34,0 +34,0 @@ "devDependencies": { |
@@ -117,2 +117,3 @@ # db-auto | ||
db-auto envs | ||
# Current environment is dev | ||
# Environment Type Host Port Database UserName | ||
@@ -124,3 +125,11 @@ # dev postgres localhost 5432 postgres phil | ||
## Current environment | ||
This defaults to 'dev'. | ||
It can be changed to another legal value by | ||
```shell | ||
db-auto env test | ||
``` | ||
## Secrets | ||
@@ -127,0 +136,0 @@ |
47056
707
142
+ Added@db-auto/dal@0.0.28(transitive)
+ Added@db-auto/environments@0.0.28(transitive)
+ Added@db-auto/files@0.0.28(transitive)
+ Added@db-auto/mocks@0.0.28(transitive)
+ Added@db-auto/mysql@0.0.28(transitive)
+ Added@db-auto/oracle@0.0.28(transitive)
+ Added@db-auto/postgres@0.0.28(transitive)
+ Added@db-auto/tables@0.0.28(transitive)
+ Added@db-auto/utils@0.0.28(transitive)
- Removed@db-auto/dal@0.0.27(transitive)
- Removed@db-auto/environments@0.0.27(transitive)
- Removed@db-auto/files@0.0.27(transitive)
- Removed@db-auto/mocks@0.0.27(transitive)
- Removed@db-auto/mysql@0.0.27(transitive)
- Removed@db-auto/oracle@0.0.27(transitive)
- Removed@db-auto/postgres@0.0.27(transitive)
- Removed@db-auto/tables@0.0.27(transitive)
- Removed@db-auto/utils@0.0.27(transitive)
Updated@db-auto/environments@0.0.28
Updated@db-auto/files@0.0.28
Updated@db-auto/mocks@0.0.28
Updated@db-auto/mysql@0.0.28
Updated@db-auto/oracle@0.0.28
Updated@db-auto/postgres@0.0.28
Updated@db-auto/tables@0.0.28
Updated@db-auto/utils@0.0.28