@polyglot-sql/sdk 0.1.8 → 0.1.9
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 +37 -0
- package/dist/cdn/polyglot.esm.js +1299 -1265
- package/dist/index.d.ts +25 -0
- package/dist/index.js +72 -1
- package/dist/polyglot_sql_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,6 +50,38 @@ console.log(sql[0]);
|
|
|
50
50
|
// x = 1
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
### Format With Guard Options
|
|
54
|
+
|
|
55
|
+
Formatting guard defaults from Rust core:
|
|
56
|
+
- `maxInputBytes`: `16 * 1024 * 1024`
|
|
57
|
+
- `maxTokens`: `1_000_000`
|
|
58
|
+
- `maxAstNodes`: `1_000_000`
|
|
59
|
+
- `maxSetOpChain`: `256`
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { formatWithOptions, Dialect } from '@polyglot-sql/sdk';
|
|
63
|
+
|
|
64
|
+
const result = formatWithOptions(
|
|
65
|
+
'SELECT a,b FROM t WHERE x=1',
|
|
66
|
+
Dialect.PostgreSQL,
|
|
67
|
+
{
|
|
68
|
+
maxInputBytes: 2 * 1024 * 1024,
|
|
69
|
+
maxTokens: 250_000,
|
|
70
|
+
maxAstNodes: 250_000,
|
|
71
|
+
maxSetOpChain: 128,
|
|
72
|
+
},
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
if (!result.success) {
|
|
76
|
+
// Includes one of:
|
|
77
|
+
// E_GUARD_INPUT_TOO_LARGE
|
|
78
|
+
// E_GUARD_TOKEN_BUDGET_EXCEEDED
|
|
79
|
+
// E_GUARD_AST_BUDGET_EXCEEDED
|
|
80
|
+
// E_GUARD_SET_OP_CHAIN_EXCEEDED
|
|
81
|
+
console.error(result.error);
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
53
85
|
## Fluent Query Builder
|
|
54
86
|
|
|
55
87
|
Build SQL queries programmatically with full type safety. All builder operations are backed by the Rust engine via WASM.
|
|
@@ -533,6 +565,10 @@ import { Polyglot, Dialect } from '@polyglot-sql/sdk';
|
|
|
533
565
|
const pg = Polyglot.getInstance();
|
|
534
566
|
const result = pg.transpile('SELECT 1', Dialect.MySQL, Dialect.PostgreSQL);
|
|
535
567
|
const formatted = pg.format('SELECT a,b FROM t');
|
|
568
|
+
const formattedSafe = pg.formatWithOptions('SELECT a,b FROM t', Dialect.Generic, {
|
|
569
|
+
maxInputBytes: 2 * 1024 * 1024,
|
|
570
|
+
maxSetOpChain: 128,
|
|
571
|
+
});
|
|
536
572
|
```
|
|
537
573
|
|
|
538
574
|
## API Reference
|
|
@@ -545,6 +581,7 @@ const formatted = pg.format('SELECT a,b FROM t');
|
|
|
545
581
|
| `parse(sql, dialect?)` | Parse SQL into AST |
|
|
546
582
|
| `generate(ast, dialect?)` | Generate SQL from AST |
|
|
547
583
|
| `format(sql, dialect?)` | Pretty-print SQL |
|
|
584
|
+
| `formatWithOptions(sql, dialect?, options?)` | Pretty-print SQL with guard overrides |
|
|
548
585
|
| `validate(sql, dialect?, options?)` | Validate SQL syntax/semantics |
|
|
549
586
|
| `validateWithSchema(sql, schema, dialect?, options?)` | Validate against a database schema |
|
|
550
587
|
| `getDialects()` | List supported dialect names |
|