@wvlet/wvlet 2025.1.11
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 +131 -0
- package/dist/lib/main.d.ts +4 -0
- package/dist/lib/main.d.ts.map +1 -0
- package/dist/lib/main.js +174058 -0
- package/dist/lib/main.js.map +1 -0
- package/dist/src/compiler.d.ts +26 -0
- package/dist/src/compiler.d.ts.map +1 -0
- package/dist/src/compiler.js +56 -0
- package/dist/src/compiler.js.map +1 -0
- package/dist/src/index.d.ts +18 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +23 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/types.d.ts +82 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +12 -0
- package/dist/src/types.js.map +1 -0
- package/lib/main.js +169153 -0
- package/lib/main.js.map +8 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Wvlet TypeScript SDK
|
|
2
|
+
|
|
3
|
+
TypeScript/JavaScript SDK for [Wvlet](https://wvlet.org/) - A flow-style query language that compiles to SQL.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @wvlet/wvlet
|
|
9
|
+
# or
|
|
10
|
+
yarn add @wvlet/wvlet
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @wvlet/wvlet
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { WvletCompiler } from '@wvlet/wvlet';
|
|
19
|
+
|
|
20
|
+
const compiler = new WvletCompiler();
|
|
21
|
+
|
|
22
|
+
// Compile a Wvlet query to SQL
|
|
23
|
+
const sql = compiler.compile('from users select name, email');
|
|
24
|
+
console.log(sql);
|
|
25
|
+
// Output: SELECT name, email FROM users
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
### Basic Compilation
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { WvletCompiler } from '@wvlet/wvlet';
|
|
34
|
+
|
|
35
|
+
const compiler = new WvletCompiler({
|
|
36
|
+
target: 'duckdb' // or 'trino'
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Compile a query
|
|
40
|
+
const sql = compiler.compile('from users where age > 18 select *');
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Error Handling
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { WvletCompiler, CompilationError } from '@wvlet/wvlet';
|
|
47
|
+
|
|
48
|
+
const compiler = new WvletCompiler();
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const sql = compiler.compile('invalid query syntax');
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (error instanceof CompilationError) {
|
|
54
|
+
console.error(`Error at line ${error.location?.line}, column ${error.location?.column}`);
|
|
55
|
+
console.error(`Message: ${error.message}`);
|
|
56
|
+
console.error(`Status: ${error.statusCode}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Convenience Function
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import { compile } from '@wvlet/wvlet';
|
|
65
|
+
|
|
66
|
+
// Use the default compiler with a single function call
|
|
67
|
+
const sql = compile('from orders select count(*)');
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## API Reference
|
|
71
|
+
|
|
72
|
+
### WvletCompiler
|
|
73
|
+
|
|
74
|
+
#### Constructor
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
new WvletCompiler(options?: CompileOptions)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Options:
|
|
81
|
+
- `target`: Target SQL dialect ('duckdb' | 'trino'). Default: 'duckdb'
|
|
82
|
+
- `profile`: Profile name for configuration
|
|
83
|
+
|
|
84
|
+
#### Methods
|
|
85
|
+
|
|
86
|
+
##### compile(query: string, options?: CompileOptions): string
|
|
87
|
+
|
|
88
|
+
Compiles a Wvlet query to SQL.
|
|
89
|
+
|
|
90
|
+
##### static getVersion(): string
|
|
91
|
+
|
|
92
|
+
Returns the version of the Wvlet compiler.
|
|
93
|
+
|
|
94
|
+
## Examples
|
|
95
|
+
|
|
96
|
+
### Query with JOIN
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
const sql = compiler.compile(`
|
|
100
|
+
from users u
|
|
101
|
+
join orders o on u.id = o.user_id
|
|
102
|
+
select u.name, count(*) as order_count
|
|
103
|
+
group by u.name
|
|
104
|
+
`);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Query with CTE
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
const sql = compiler.compile(`
|
|
111
|
+
with active_users as (
|
|
112
|
+
from users
|
|
113
|
+
where last_login > current_date - interval '30 days'
|
|
114
|
+
select *
|
|
115
|
+
)
|
|
116
|
+
from active_users
|
|
117
|
+
select name, email
|
|
118
|
+
`);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Browser Support
|
|
122
|
+
|
|
123
|
+
This SDK works in both Node.js and modern browsers that support ES modules.
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
Apache License 2.0
|
|
128
|
+
|
|
129
|
+
## Contributing
|
|
130
|
+
|
|
131
|
+
See the [main Wvlet repository](https://github.com/wvlet/wvlet) for contribution guidelines.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../lib/main.js"],"names":[],"mappings":"AA4rqKA,4BAAkD;AAElD,wBAAuC"}
|