Comparing version 0.0.30 to 0.1.0
#!/usr/bin/env node | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const utils_1 = require("@db-auto/utils"); | ||
const utils_1 = require("@dbpath/utils"); | ||
const cli_1 = require("./src/cli"); | ||
@@ -6,0 +6,0 @@ let cwd = process.cwd(); |
import { Command } from "commander"; | ||
import { ErrorsAnd, NameAnd } from "@db-auto/utils"; | ||
import { ErrorsAnd, NameAnd } from "@dbpath/utils"; | ||
import { CleanConfig } from "./config"; | ||
@@ -4,0 +4,0 @@ export declare function makeConfig(cwd: string, envVars: NameAnd<string>): ErrorsAnd<CleanConfig>; |
@@ -14,8 +14,8 @@ "use strict"; | ||
const commander_1 = require("commander"); | ||
const utils_1 = require("@db-auto/utils"); | ||
const tables_1 = require("@db-auto/tables"); | ||
const mocks_1 = require("@db-auto/mocks"); | ||
const utils_1 = require("@dbpath/utils"); | ||
const tables_1 = require("@dbpath/tables"); | ||
const mocks_1 = require("@dbpath/mocks"); | ||
const config_1 = require("./config"); | ||
const files_1 = require("@db-auto/files"); | ||
const environments_1 = require("@db-auto/environments"); | ||
const files_1 = require("@dbpath/files"); | ||
const environments_1 = require("@dbpath/environments"); | ||
const path_1 = require("./path"); | ||
@@ -22,0 +22,0 @@ function makeConfig(cwd, envVars) { |
@@ -1,4 +0,4 @@ | ||
import { NameAnd, NameAndValidator } from "@db-auto/utils"; | ||
import { CleanTable, Table } from "@db-auto/tables"; | ||
import { CleanEnvironment, Environment } from "@db-auto/environments"; | ||
import { NameAnd, NameAndValidator } from "@dbpath/utils"; | ||
import { CleanTable, Table } from "@dbpath/tables"; | ||
import { CleanEnvironment, Environment } from "@dbpath/environments"; | ||
export interface Config { | ||
@@ -5,0 +5,0 @@ environments: NameAnd<Environment>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.envValidator = exports.cleanConfig = void 0; | ||
const utils_1 = require("@db-auto/utils"); | ||
const tables_1 = require("@db-auto/tables"); | ||
const environments_1 = require("@db-auto/environments"); | ||
const utils_1 = require("@dbpath/utils"); | ||
const tables_1 = require("@dbpath/tables"); | ||
const environments_1 = require("@dbpath/environments"); | ||
const cleanConfig = (envVars) => (config) => ({ | ||
@@ -8,0 +8,0 @@ environments: (0, environments_1.cleanEnvironment)(envVars, config.environments), |
import { Config } from "./config"; | ||
import { NameAndValidator } from "@db-auto/utils"; | ||
import { Environment } from "@db-auto/tables"; | ||
import { NameAndValidator } from "@dbpath/utils"; | ||
import { Environment } from "@dbpath/tables"; | ||
export declare const environmentValidator: NameAndValidator<Environment>; | ||
export declare const configValidator: NameAndValidator<Config>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.configValidator = exports.environmentValidator = void 0; | ||
const utils_1 = require("@db-auto/utils"); | ||
const tables_1 = require("@db-auto/tables"); | ||
const utils_1 = require("@dbpath/utils"); | ||
const tables_1 = require("@dbpath/tables"); | ||
exports.environmentValidator = (0, utils_1.composeNameAndValidators)((0, utils_1.validateChildValue)('type', 'oracle', 'mysql'), (0, utils_1.validateChildString)('url'), (0, utils_1.validateChildString)('username', true), (0, utils_1.validateChildString)('password', true)); | ||
exports.configValidator = (0, utils_1.composeNameAndValidators)((0, utils_1.validateChildDefined)('environments'), (0, utils_1.validateChild)('environments', (0, utils_1.validateNameAnd)(exports.environmentValidator)), (0, utils_1.validateChildDefined)('tables'), (0, utils_1.validateChild)('tables', (0, utils_1.validateNameAnd)(tables_1.tableValidator))); |
@@ -9,6 +9,6 @@ "use strict"; | ||
const path_1 = __importDefault(require("path")); | ||
const files_1 = require("@db-auto/files"); | ||
const files_1 = require("@dbpath/files"); | ||
const child_process_1 = __importDefault(require("child_process")); | ||
const path_2 = __importDefault(require("path")); | ||
const utils_1 = require("@db-auto/utils"); | ||
const utils_1 = require("@dbpath/utils"); | ||
exports.codeRootDir = (0, files_1.findDirectoryHoldingFileOrThrow)(process.cwd(), "laoban.json"); | ||
@@ -15,0 +15,0 @@ exports.testRoot = path_1.default.resolve(exports.codeRootDir, '..', 'tests'); |
@@ -13,3 +13,3 @@ "use strict"; | ||
const integration_fixture_1 = require("./integration.fixture"); | ||
const files_1 = require("@db-auto/files"); | ||
const files_1 = require("@dbpath/files"); | ||
const mockTestDir = integration_fixture_1.testRoot + '/simple'; | ||
@@ -16,0 +16,0 @@ const inCi = process.env['CI'] === 'true'; |
@@ -1,5 +0,5 @@ | ||
import { ErrorsAnd, NameAnd } from "@db-auto/utils"; | ||
import { CleanTable, PathSpec, SelectData, SqlOptions } from "@db-auto/tables"; | ||
import { EnvAndName } from "@db-auto/environments"; | ||
import { DalResult, DalResultDisplayOptions } from "@db-auto/dal"; | ||
import { ErrorsAnd, NameAnd } from "@dbpath/utils"; | ||
import { CleanTable, PathSpec, SelectData, SqlOptions } from "@dbpath/tables"; | ||
import { EnvAndName } from "@dbpath/environments"; | ||
import { DalResult, DalResultDisplayOptions } from "@dbpath/dal"; | ||
export interface SelectDataPP { | ||
@@ -6,0 +6,0 @@ type: 'selectData'; |
@@ -13,6 +13,6 @@ "use strict"; | ||
exports.tracePlan = exports.makeTracePlanSpecs = exports.prettyPrintPP = exports.processPathString = void 0; | ||
const utils_1 = require("@db-auto/utils"); | ||
const tables_1 = require("@db-auto/tables"); | ||
const environments_1 = require("@db-auto/environments"); | ||
const dal_1 = require("@db-auto/dal"); | ||
const utils_1 = require("@dbpath/utils"); | ||
const tables_1 = require("@dbpath/tables"); | ||
const environments_1 = require("@dbpath/environments"); | ||
const dal_1 = require("@dbpath/dal"); | ||
function findLinks(tables, path) { | ||
@@ -19,0 +19,0 @@ let withoutQuery = path.slice(0, -1); |
@@ -13,5 +13,5 @@ "use strict"; | ||
const path_1 = require("./path"); | ||
const tables_1 = require("@db-auto/tables"); | ||
const utils_1 = require("@db-auto/utils"); | ||
const environments_1 = require("@db-auto/environments"); | ||
const tables_1 = require("@dbpath/tables"); | ||
const utils_1 = require("@dbpath/utils"); | ||
const environments_1 = require("@dbpath/environments"); | ||
const envAndName = { env: environments_1.cleanEnv.dev, envName: 'dev' }; | ||
@@ -18,0 +18,0 @@ describe('processPath', () => { |
{ | ||
"name": "dbpath", | ||
"description": "", | ||
"version": "0.0.30", | ||
"version": "0.1.0", | ||
"main": "dist/index", | ||
"types": "dist/index", | ||
"bin": { | ||
"db-auto": "dist/index.js" | ||
"dbpath": "dist/index.js" | ||
}, | ||
@@ -24,10 +24,10 @@ "browserslist": { | ||
"commander": "^10.0.0", | ||
"@db-auto/oracle": "0.0.30", | ||
"@db-auto/mysql": "0.0.30", | ||
"@db-auto/postgres": "0.0.30", | ||
"@db-auto/tables": "0.0.30", | ||
"@db-auto/utils": "0.0.30", | ||
"@db-auto/files": "0.0.30", | ||
"@db-auto/mocks": "0.0.30", | ||
"@db-auto/environments": "0.0.30" | ||
"@dbpath/oracle": "0.1.0", | ||
"@dbpath/mysql": "0.1.0", | ||
"@dbpath/postgres": "0.1.0", | ||
"@dbpath/tables": "0.1.0", | ||
"@dbpath/utils": "0.1.0", | ||
"@dbpath/files": "0.1.0", | ||
"@dbpath/mocks": "0.1.0", | ||
"@dbpath/environments": "0.1.0" | ||
}, | ||
@@ -34,0 +34,0 @@ "devDependencies": { |
153
README.md
@@ -1,152 +0,1 @@ | ||
# db-auto | ||
Automation of database scripts: turning results to jq to simply scripting for support and diagnostics | ||
## Current state: | ||
We have a command line tool `db-auto` that 'knows' a little about the database structure. This knowledge is | ||
in a file called `db-auto.json`. This file is in the current directory or a parent. | ||
The tool just does simple queries that joins tables together. It is intended for support people that need to walk tables. | ||
Often these people often have a notepad full of common queries that they copy and paste into the database tool. This | ||
tool is intended to subliment that, and make it easy to do the same thing from the command line. | ||
```shell | ||
db-auto ? # lists the tables | ||
db-auto d? # lists the tables that start with d | ||
db-auto driver 123 # lists the driver with id 123 | ||
db-auto driver --name phil # lists the driver with name phil | ||
db-auto driver.audit 123 # lists the audit records for driver 123 (the records for driver are joined to the audit records) | ||
db-auto driver.mission.audit 123 # lists the audit records for the missions that driver 123 has been on | ||
db-auto driver.mission.audit 123 -date '2023-6-3' # lists the audit records for the missions that driver 123 has been on for the given date | ||
``` | ||
The sql queries are derived from a knowledge of the database that is in the `db-auto.json` file. Currently, | ||
this has to be populated manually, but I expect to auto generate it from the database schema. | ||
# Features | ||
## -s or --sql or --fullSql | ||
Show the sql instead of executing it. FullSql includes the paging sql (which can be 'noisy') | ||
```shell | ||
db-auto driver 123 -s | ||
# select T0.* | ||
# from DriverTable T0 where T0.driverId=123 | ||
db-auto driver 123 --fullSql | ||
# select T0.* | ||
# from DriverTable T0 where T0.driverId=123 | ||
# LIMIT 15 OFFSET 0 | ||
``` | ||
## -t or --trace | ||
Execute the command one step at a time, showing the sql and the results | ||
```shell | ||
db-auto driver.mission.audit 123 -ts | ||
``` | ||
## -w or --where | ||
Add a where clause to the query. Typically you would do a `-s` first to find the alias name | ||
```shell | ||
db-auto driver.mission.audit -w 'audit.id = 123' | ||
db-auto driver -w 'T0.name = "phil"' # Note the need for the quotes. This is because the shell is parsing the command line | ||
``` | ||
## -c or --count | ||
Show the count of the results instead of the results | ||
```shell | ||
db-auto driver --count | ||
# count | ||
# 2 | ||
db-auto driver --count --notitles | ||
# 2 | ||
``` | ||
## --distinct | ||
Show the distinct values of the results | ||
## --notitles | ||
Don't show the titles on results. This can help a lot when making scripts that use the output | ||
```shell | ||
db-auto driver --notitles | ||
# 1 phil | ||
# 2 joe | ||
``` | ||
## --json | ||
Show the results as json. This is useful for piping to jq | ||
```shell | ||
db-auto driver --json | ||
# [ | ||
# { | ||
# "driverid": 1, | ||
# "name": "phil" | ||
# }, | ||
# { | ||
# "driverid": 2, | ||
# "name": "joe" | ||
# } | ||
# ] | ||
``` | ||
##--onelinejson | ||
```shell | ||
db-auto driver --onelinejson | ||
# {"driverid":1,"name":"phil"} | ||
# {"driverid":2,"name":"joe"} | ||
``` | ||
# Environments | ||
Typically, we have multiple environments. The tool can be configured to use different databases for different environments: | ||
this is in the `db-auto.json` file. The default environment is `dev` (and in current state that's the only one usable) | ||
The environment gives the database type and the connection details | ||
```shell | ||
db-auto envs | ||
# Current environment is dev | ||
# Environment Type Host Port Database UserName | ||
# dev postgres localhost 5432 postgres phil | ||
# test 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 | ||
``` | ||
## Checking the environments are accessible | ||
```shell | ||
db-auto status | ||
#Environment Type Host Port Database UserName Up | ||
#dev postgres localhost 5432 postgres phil true | ||
#test postgres test.example.com 5432 postgres phil true | ||
``` | ||
## Secrets | ||
The username and password don't need to be specified if they are in environment variables: | ||
* DB_AUTO_<env>_USERNAME provides the username. For example `export DB_AUTO_DEV_USERNAME=phil` | ||
* DB_AUTO_<env>_PASSWORD provides the password. For example `export DB_AUTO_DEV_PASSWORD=phil` | ||
Moved to package @dbpath |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44909
1
+ Added@dbpath/environments@0.1.0
+ Added@dbpath/files@0.1.0
+ Added@dbpath/mocks@0.1.0
+ Added@dbpath/mysql@0.1.0
+ Added@dbpath/oracle@0.1.0
+ Added@dbpath/postgres@0.1.0
+ Added@dbpath/tables@0.1.0
+ Added@dbpath/utils@0.1.0
+ Added@dbpath/dal@0.1.0(transitive)
+ Added@dbpath/environments@0.1.0(transitive)
+ Added@dbpath/files@0.1.0(transitive)
+ Added@dbpath/mocks@0.1.0(transitive)
+ Added@dbpath/mysql@0.1.0(transitive)
+ Added@dbpath/oracle@0.1.0(transitive)
+ Added@dbpath/postgres@0.1.0(transitive)
+ Added@dbpath/tables@0.1.0(transitive)
+ Added@dbpath/utils@0.1.0(transitive)
- Removed@db-auto/environments@0.0.30
- Removed@db-auto/files@0.0.30
- Removed@db-auto/mocks@0.0.30
- Removed@db-auto/mysql@0.0.30
- Removed@db-auto/oracle@0.0.30
- Removed@db-auto/postgres@0.0.30
- Removed@db-auto/tables@0.0.30
- Removed@db-auto/utils@0.0.30
- Removed@db-auto/dal@0.0.30(transitive)
- Removed@db-auto/environments@0.0.30(transitive)
- Removed@db-auto/files@0.0.30(transitive)
- Removed@db-auto/mocks@0.0.30(transitive)
- Removed@db-auto/mysql@0.0.30(transitive)
- Removed@db-auto/oracle@0.0.30(transitive)
- Removed@db-auto/postgres@0.0.30(transitive)
- Removed@db-auto/tables@0.0.30(transitive)
- Removed@db-auto/utils@0.0.30(transitive)