Skip to content

Commit 6029a28

Browse files
committed
readmes
1 parent e299321 commit 6029a28

File tree

5 files changed

+16
-30
lines changed

5 files changed

+16
-30
lines changed

DEPARSER_USAGE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,15 @@ These ensure proper handling of different input formats automatically.
218218
### Complete Example
219219

220220
```typescript
221-
import deparse from 'pgsql-deparser';
221+
import { deparse } from 'pgsql-deparser';
222222
import { parse } from 'pgsql-parser';
223223

224224
// Parse SQL
225225
const sql = 'SELECT * FROM users; INSERT INTO logs (action) VALUES ($1);';
226-
const parseResult = parse(sql);
226+
const parseResult = await parse(sql);
227227

228228
// Deparse back to SQL
229-
const regeneratedSql = deparse(parseResult);
229+
const regeneratedSql = await deparse(parseResult);
230230
console.log(regeneratedSql);
231231
// Output: "SELECT * FROM users;\n\nINSERT INTO logs (action) VALUES ($1);"
232232
```
@@ -252,6 +252,6 @@ const customSelect = {
252252
}
253253
};
254254

255-
const sql = deparse(customSelect);
255+
const sql = await deparse(customSelect);
256256
// Output: "SELECT * FROM users"
257257
```

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ console.log(sql); // SELECT * FROM users WHERE id = 1
7474
#### Build AST Programmatically
7575
```typescript
7676
import * as t from '@pgsql/utils';
77-
import { RangeVar, SelectStmt } from '@pgsql/types';
77+
import { SelectStmt } from '@pgsql/types';
7878

7979
const stmt: { SelectStmt: SelectStmt } = t.nodes.selectStmt({
8080
targetList: [
@@ -127,9 +127,6 @@ yarn install
127127

128128
# Build all packages
129129
yarn build
130-
131-
# Run tests
132-
yarn test
133130
```
134131

135132
### Building Individual Packages
@@ -163,15 +160,15 @@ const ast = await parse('SELECT * FROM users WHERE active = true');
163160
ast[0].RawStmt.stmt.SelectStmt.fromClause[0].RangeVar.relname = 'customers';
164161

165162
// Generate the modified SQL
166-
const newSql = deparse(ast);
163+
const newSql = await deparse(ast);
167164
console.log(newSql); // SELECT * FROM customers WHERE active = TRUE
168165
```
169166

170167
### Build a Query Programmatically
171168

172169
```typescript
173170
import ast from '@pgsql/utils';
174-
import { deparse as deparseSync } from 'pgsql-deparser';
171+
import { deparse } from 'pgsql-deparser';
175172

176173
const query: { SelectStmt: SelectStmt } = t.nodes.selectStmt({
177174
targetList: [
@@ -207,7 +204,7 @@ const query: { SelectStmt: SelectStmt } = t.nodes.selectStmt({
207204
op: 'SETOP_NONE'
208205
});
209206

210-
console.log(deparse(query));
207+
console.log(await deparse(query));
211208
// SELECT name, email FROM users WHERE age > 18
212209
```
213210

TESTS.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/parser/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Here's how you can use the deparser in your TypeScript code, using [`@pgsql/util
9191
```ts
9292
import * as t from '@pgsql/utils';
9393
import { RangeVar, SelectStmt } from '@pgsql/types';
94-
import { deparseSync as deparse } from 'pgsql-deparser';
94+
import { deparse } from 'pgsql-deparser';
9595

9696
// This could have been obtained from any JSON or AST, not necessarily @pgsql/utils
9797
const stmt: { SelectStmt: SelectStmt } = t.nodes.selectStmt({
@@ -117,7 +117,7 @@ const stmt: { SelectStmt: SelectStmt } = t.nodes.selectStmt({
117117
(stmt.SelectStmt.fromClause[0] as {RangeVar: RangeVar}).RangeVar.relname = 'another_table';
118118

119119
// Deparse the modified AST back to a SQL string
120-
console.log(deparse(stmt));
120+
console.log(await deparse(stmt));
121121

122122
// Output: SELECT * FROM another_table
123123
```

packages/utils/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Explore the PostgreSQL Abstract Syntax Tree (AST) as JSON objects with ease usin
6161
```ts
6262
import * as t from '@pgsql/utils';
6363
import { SelectStmt } from '@pgsql/types';
64-
import { deparseSync as deparse } from 'pgsql-deparser';
64+
import { deparse } from 'pgsql-deparser';
6565

6666
const selectStmt: { SelectStmt: SelectStmt } = t.nodes.selectStmt({
6767
targetList: [
@@ -83,16 +83,16 @@ const selectStmt: { SelectStmt: SelectStmt } = t.nodes.selectStmt({
8383
});
8484
console.log(selectStmt);
8585
// Output: { "SelectStmt": { "targetList": [ { "ResTarget": { "val": { "ColumnRef": { "fields": [ { "A_Star": {} } ] } } } } ], "fromClause": [ { "RangeVar": { "relname": "some_amazing_table", "inh": true, "relpersistence": "p" } } ], "limitOption": "LIMIT_OPTION_DEFAULT", "op": "SETOP_NONE" } }
86-
console.log(deparse(stmt))
86+
console.log(await deparse(stmt))
8787
// Output: SELECT * FROM some_amazing_table
8888
```
8989

9090
#### Select Statement
9191

9292
```ts
9393
import * as t from '@pgsql/utils';
94-
import { RangeVar, SelectStmt } from '@pgsql/types';
95-
import { deparseSync as deparse } from 'pgsql-deparser';
94+
import { SelectStmt } from '@pgsql/types';
95+
import { deparse } from 'pgsql-deparser';
9696

9797
const query: { SelectStmt: SelectStmt } = t.nodes.selectStmt({
9898
targetList: [
@@ -128,7 +128,7 @@ const query: { SelectStmt: SelectStmt } = t.nodes.selectStmt({
128128
op: 'SETOP_NONE'
129129
});
130130

131-
deparse(createStmt, {});
131+
await deparse(createStmt);
132132
// SELECT name, email FROM users WHERE age > 18
133133
```
134134

@@ -167,7 +167,7 @@ const createStmt = t.nodes.createStmt({
167167
});
168168

169169
// `deparse` function converts AST to SQL string
170-
const sql = deparse(createStmt);
170+
const sql = await deparse(createStmt, { pretty: true });
171171

172172
console.log(sql);
173173
// OUTPUT:

0 commit comments

Comments
 (0)