Skip to content

Commit 13109b8

Browse files
author
Søren Hansen
authored
make d.ts files specific to the lib (#25)
1 parent 99babd3 commit 13109b8

5 files changed

Lines changed: 22 additions & 22 deletions

File tree

File renamed without changes.
File renamed without changes.

npm-package/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ npx @squeeel/cli gen
2727

2828
The database url, used libraries and such are automatically detected. If you need to configure anything, please run `npx @squeeel/cli gen --help` to get a list of configuration options.
2929

30-
That's it! Your SQL queries are now type-safe. The tool will generate a `squeeel.d.ts` file with all the necessary type definitions.
30+
That's it! Your SQL queries are now type-safe. The tool will generate a `squeeel.<lib-name>.d.ts` file with all the necessary type definitions.
3131

3232
## Example
3333

3434
This example is using node-postgres:
3535

36-
After running squeeel
36+
After running squeeel, a `squeeel.pg.d.ts` file will be generated, and
3737

3838
```typescript
3939
const result = await client.query(
4040
"SELECT id, name, age FROM users WHERE age >= $1",
41-
// Typescript knows the types the arguments need to have
41+
// Typescript knows the types the arguments need to have, e.g. ["something"] would be an error
4242
[18]
4343
);
4444

@@ -58,7 +58,7 @@ const result = await client.query(
5858

5959
### Unsupported Libraries
6060

61-
Due to TypeScript limitations with tagged templates, we cannot support:
61+
Due to TypeScript limitations with tagged templates not being generic, we cannot support:
6262
- postgres.js
6363
- @vercel/postgres
6464
- bun-sql

squeeel-cli/src/main.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ async fn create_d_ts_files(
296296
let mut tasks = Vec::with_capacity(queries_by_lib.keys().len());
297297
for (lib, queries) in queries_by_lib {
298298
tasks.push(tokio::spawn({
299-
async move { lib.create_d_ts_file(queries).await }
299+
async move { (lib, lib.create_d_ts_file(queries).await) }
300300
}));
301301
}
302302

@@ -305,28 +305,28 @@ async fn create_d_ts_files(
305305
outputs.push(task.await.unwrap());
306306
}
307307

308-
let cm: Lrc<SourceMap> = Default::default();
309-
let code = {
310-
let mut buf = Vec::new();
308+
for (lib, module) in outputs {
309+
let cm: Lrc<SourceMap> = Default::default();
310+
let code = {
311+
let mut buf = Vec::new();
312+
313+
{
314+
let mut emitter = Emitter {
315+
cfg: Default::default(),
316+
cm: cm.clone(),
317+
comments: None,
318+
wr: JsWriter::new(cm, "\n", &mut buf, None),
319+
};
311320

312-
{
313-
let mut emitter = Emitter {
314-
cfg: Default::default(),
315-
cm: cm.clone(),
316-
comments: None,
317-
wr: JsWriter::new(cm, "\n", &mut buf, None),
318-
};
319-
320-
for module in outputs {
321321
emitter.emit_module(&module).unwrap();
322322
}
323-
}
324323

325-
String::from_utf8_lossy(&buf).to_string()
326-
};
324+
String::from_utf8_lossy(&buf).to_string()
325+
};
327326

328-
let d_ts_path = dir.join("src/squeeel.d.ts");
329-
std::fs::write(d_ts_path, code).unwrap();
327+
let d_ts_path = dir.join(format!("src/squeeel.{lib}.d.ts"));
328+
std::fs::write(d_ts_path, code).unwrap();
329+
}
330330

331331
Ok(())
332332
}

0 commit comments

Comments
 (0)