@sqlike/cli 0.1.0
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/README.md +51 -0
- package/bin/sqlike.js +57 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# @sqlike/cli
|
|
2
|
+
|
|
3
|
+
Command-line client for [sqlike](https://sqlike.com) — a deterministic SQL static analyzer and
|
|
4
|
+
advisor (validity, anti-patterns, rewrites, schema advice) and query-equivalence checker for
|
|
5
|
+
Postgres, MySQL, SQLite, and SQL Server.
|
|
6
|
+
|
|
7
|
+
This package is a **thin remote client**: it tokenizes your SQL locally (identifiers and literals
|
|
8
|
+
are replaced before anything leaves your machine) and forwards the tokenized query to the sqlike
|
|
9
|
+
API. It contains no analysis engine.
|
|
10
|
+
|
|
11
|
+
## Use it
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
# analyze a query
|
|
15
|
+
npx @sqlike/cli check query.sql --remote https://api.sqlike.com
|
|
16
|
+
|
|
17
|
+
# or install it
|
|
18
|
+
npm i -g @sqlike/cli
|
|
19
|
+
sqlike check query.sql --remote https://api.sqlike.com
|
|
20
|
+
|
|
21
|
+
# from stdin, machine-readable
|
|
22
|
+
echo 'SELECT * FROM users WHERE id IN (SELECT uid FROM bans)' \
|
|
23
|
+
| sqlike check - --remote https://api.sqlike.com --json
|
|
24
|
+
|
|
25
|
+
# check a rewrite is equivalent (equivalence always runs server-side)
|
|
26
|
+
sqlike diff before.sql after.sql --schema schema.sql
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Pass `--dialect postgres|mysql|sqlite|mssql` (default postgres), `--schema <ddl-file>` for
|
|
30
|
+
column- and type-aware checks, and `--key <api-key>` for higher rate limits.
|
|
31
|
+
|
|
32
|
+
Exit codes are a contract: `0` clean / equivalent, `1` advisory / differs, `2` blocking issue /
|
|
33
|
+
undecided, `3` operational error.
|
|
34
|
+
|
|
35
|
+
### Privacy
|
|
36
|
+
|
|
37
|
+
A query is tokenized before it leaves your machine. A query that can't be parsed can't be
|
|
38
|
+
tokenized, so `check`/`diff` refuse rather than send raw SQL; pass `--allow-raw` (with `--remote`)
|
|
39
|
+
to override for a parse diagnostic.
|
|
40
|
+
|
|
41
|
+
## How it ships
|
|
42
|
+
|
|
43
|
+
The CLI is a native binary. Each platform's binary is published as its own optional-dependency
|
|
44
|
+
package (`@sqlike/cli-linux-x64`, `@sqlike/cli-darwin-arm64`, …); npm installs only the one matching
|
|
45
|
+
your OS and CPU. No install scripts run — this works with `--ignore-scripts` and in locked-down
|
|
46
|
+
environments. Supported: linux x64/arm64, macOS x64/arm64, Windows x64. Also available via Homebrew
|
|
47
|
+
(`brew install orifisher2/sqlike/sqlike`).
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
MIT OR Apache-2.0
|
package/bin/sqlike.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
// Launcher for the sqlike CLI. `sqlike` is a small native binary that forwards to
|
|
5
|
+
// the sqlike API (tokenizing locally first); each supported platform ships its
|
|
6
|
+
// binary as a dedicated optional-dependency package, so npm installs only the one
|
|
7
|
+
// whose os/cpu match and the user downloads a single binary. This script locates
|
|
8
|
+
// that binary and execs it, passing argv and stdio through unchanged.
|
|
9
|
+
|
|
10
|
+
const path = require('node:path');
|
|
11
|
+
const { spawnSync } = require('node:child_process');
|
|
12
|
+
|
|
13
|
+
// Keep in sync with optionalDependencies in package.json.
|
|
14
|
+
const PACKAGES = {
|
|
15
|
+
'darwin-arm64': '@sqlike/cli-darwin-arm64',
|
|
16
|
+
'darwin-x64': '@sqlike/cli-darwin-x64',
|
|
17
|
+
'linux-arm64': '@sqlike/cli-linux-arm64',
|
|
18
|
+
'linux-x64': '@sqlike/cli-linux-x64',
|
|
19
|
+
'win32-x64': '@sqlike/cli-win32-x64',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function resolveBinary() {
|
|
23
|
+
const key = `${process.platform}-${process.arch}`;
|
|
24
|
+
const pkg = PACKAGES[key];
|
|
25
|
+
if (!pkg) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`no prebuilt binary for ${key}; supported: ${Object.keys(PACKAGES).join(', ')}`,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
const exe = process.platform === 'win32' ? 'sqlike.exe' : 'sqlike';
|
|
31
|
+
// Resolve via package.json (always accessible) then join the binary name.
|
|
32
|
+
const pkgDir = path.dirname(require.resolve(`${pkg}/package.json`));
|
|
33
|
+
return path.join(pkgDir, exe);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let bin;
|
|
37
|
+
try {
|
|
38
|
+
bin = resolveBinary();
|
|
39
|
+
} catch (err) {
|
|
40
|
+
process.stderr.write(
|
|
41
|
+
`sqlike: ${err.message}. ` +
|
|
42
|
+
`If your platform should be supported, reinstall without --no-optional.\n`,
|
|
43
|
+
);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// stdio: 'inherit' gives the child our real stdin/stdout/stderr so piping SQL in and
|
|
48
|
+
// reading the report out works unchanged; exit code is forwarded (the CLI uses it as
|
|
49
|
+
// a contract: 0 ok, 1 warn/differs, 2 block/undecided, 3 operational error).
|
|
50
|
+
const { status, signal, error } = spawnSync(bin, process.argv.slice(2), {
|
|
51
|
+
stdio: 'inherit',
|
|
52
|
+
});
|
|
53
|
+
if (error) {
|
|
54
|
+
process.stderr.write(`sqlike: failed to start ${bin}: ${error.message}\n`);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
process.exit(signal ? 1 : status ?? 0);
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sqlike/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI for sqlike — deterministic SQL static analysis and query-equivalence checking. A thin remote client that tokenizes locally and forwards to the sqlike API.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"sql",
|
|
7
|
+
"sqlike",
|
|
8
|
+
"cli",
|
|
9
|
+
"static-analysis",
|
|
10
|
+
"linter",
|
|
11
|
+
"postgres",
|
|
12
|
+
"mysql",
|
|
13
|
+
"sqlite",
|
|
14
|
+
"sqlserver"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://sqlike.com",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/orifisher2/sqlike.git",
|
|
20
|
+
"directory": "packages/cli"
|
|
21
|
+
},
|
|
22
|
+
"license": "(MIT OR Apache-2.0)",
|
|
23
|
+
"bin": {
|
|
24
|
+
"sqlike": "bin/sqlike.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"bin"
|
|
28
|
+
],
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18"
|
|
31
|
+
},
|
|
32
|
+
"optionalDependencies": {
|
|
33
|
+
"@sqlike/cli-darwin-arm64": "0.1.0",
|
|
34
|
+
"@sqlike/cli-darwin-x64": "0.1.0",
|
|
35
|
+
"@sqlike/cli-linux-arm64": "0.1.0",
|
|
36
|
+
"@sqlike/cli-linux-x64": "0.1.0",
|
|
37
|
+
"@sqlike/cli-win32-x64": "0.1.0"
|
|
38
|
+
}
|
|
39
|
+
}
|