Skip to content

Commit b6c8044

Browse files
Reorganize README structure - move Usage above Build Instructions
- Move Documentation section above Build Instructions and rename to 'Usage' - Update Table of Contents to reflect new section order - Remove 'Expected Test Output' section from Testing as requested - Improve README flow with Usage information appearing earlier Co-Authored-By: Dan Lynch <[email protected]>
1 parent c101cc0 commit b6c8044

File tree

1 file changed

+72
-90
lines changed

1 file changed

+72
-90
lines changed

README.md

Lines changed: 72 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ A WASM-based PostgreSQL query parser that provides the same functionality as the
2424

2525
1. [Installation](#installation)
2626
2. [Example](#example)
27-
3. [Build Instructions](#build-instructions)
28-
4. [Testing](#testing)
29-
5. [Documentation](#documentation)
27+
3. [Usage](#usage)
28+
4. [Build Instructions](#build-instructions)
29+
5. [Testing](#testing)
3030
6. [Versions](#versions)
3131
7. [Related Projects](#related-projects)
3232
8. [Credit](#credit)
@@ -60,93 +60,7 @@ const { parseQuery, parseQuerySync } = require('libpg-query');
6060
parseQuery('SELECT * FROM users WHERE id = $1').then(console.log);
6161
```
6262

63-
## Build Instructions
64-
65-
This package uses a **WASM-only build system** for true cross-platform compatibility without native compilation dependencies.
66-
67-
### Prerequisites
68-
69-
- Node.js (version 16 or higher recommended)
70-
- Docker (for WASM compilation using Emscripten)
71-
- yarn or npm
72-
73-
### Building WASM Artifacts
74-
75-
1. **Install dependencies:**
76-
```bash
77-
npm install
78-
# or
79-
yarn install
80-
```
81-
82-
2. **Build WASM artifacts:**
83-
```bash
84-
npm run wasm:build
85-
# or
86-
yarn wasm:build
87-
```
88-
89-
3. **Clean WASM build (if needed):**
90-
```bash
91-
npm run wasm:clean
92-
# or
93-
yarn wasm:clean
94-
```
95-
96-
4. **Rebuild WASM artifacts from scratch:**
97-
```bash
98-
npm run wasm:clean && npm run wasm:build
99-
# or
100-
yarn wasm:clean && yarn wasm:build
101-
```
102-
103-
### Build Process Details
104-
105-
The WASM build process:
106-
- Uses Docker with Emscripten SDK for compilation
107-
- Compiles C wrapper code to WebAssembly
108-
- Generates `wasm/libpg-query.js` and `wasm/libpg-query.wasm` files
109-
- No native compilation or node-gyp dependencies required
110-
111-
## Testing
112-
113-
### Running Tests
114-
115-
```bash
116-
npm test
117-
# or
118-
yarn test
119-
```
120-
121-
### Test Requirements
122-
123-
- WASM artifacts must be built before running tests
124-
- If tests fail with "fetch failed" errors, rebuild WASM artifacts:
125-
```bash
126-
npm run wasm:clean && npm run wasm:build && npm test
127-
```
128-
129-
### Expected Test Output
130-
131-
All tests should pass:
132-
```
133-
Queries
134-
Sync Parsing
135-
✓ should return a single-item parse result for common queries
136-
✓ should support parsing multiple queries
137-
✓ should not parse a bogus query
138-
Async parsing
139-
✓ should return a promise resolving to same result
140-
✓ should reject on bogus queries
141-
Deparsing
142-
✓ async function should return a promise resolving to same SQL
143-
✓ sync function should return a same SQL
144-
[... more tests ...]
145-
146-
18 passing (70ms)
147-
```
148-
149-
## Documentation
63+
## Usage
15064

15165
### `parseQuery(sql: string): Promise<ParseResult[]>`
15266

@@ -216,6 +130,74 @@ interface Statement {
216130

217131
**Note:** The return value is an array, as multiple queries may be provided in a single string (semicolon-delimited, as PostgreSQL expects).
218132

133+
## Build Instructions
134+
135+
This package uses a **WASM-only build system** for true cross-platform compatibility without native compilation dependencies.
136+
137+
### Prerequisites
138+
139+
- Node.js (version 16 or higher recommended)
140+
- Docker (for WASM compilation using Emscripten)
141+
- yarn or npm
142+
143+
### Building WASM Artifacts
144+
145+
1. **Install dependencies:**
146+
```bash
147+
npm install
148+
# or
149+
yarn install
150+
```
151+
152+
2. **Build WASM artifacts:**
153+
```bash
154+
npm run wasm:build
155+
# or
156+
yarn wasm:build
157+
```
158+
159+
3. **Clean WASM build (if needed):**
160+
```bash
161+
npm run wasm:clean
162+
# or
163+
yarn wasm:clean
164+
```
165+
166+
4. **Rebuild WASM artifacts from scratch:**
167+
```bash
168+
npm run wasm:clean && npm run wasm:build
169+
# or
170+
yarn wasm:clean && yarn wasm:build
171+
```
172+
173+
### Build Process Details
174+
175+
The WASM build process:
176+
- Uses Docker with Emscripten SDK for compilation
177+
- Compiles C wrapper code to WebAssembly
178+
- Generates `wasm/libpg-query.js` and `wasm/libpg-query.wasm` files
179+
- No native compilation or node-gyp dependencies required
180+
181+
## Testing
182+
183+
### Running Tests
184+
185+
```bash
186+
npm test
187+
# or
188+
yarn test
189+
```
190+
191+
### Test Requirements
192+
193+
- WASM artifacts must be built before running tests
194+
- If tests fail with "fetch failed" errors, rebuild WASM artifacts:
195+
```bash
196+
npm run wasm:clean && npm run wasm:build && npm test
197+
```
198+
199+
200+
219201
## Versions
220202

221203
Our latest is built with `17-latest` branch from libpg_query

0 commit comments

Comments
 (0)