@sqldoc/templates 0.0.1 → 0.0.2

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.
Files changed (70) hide show
  1. package/package.json +10 -8
  2. package/src/__tests__/dedent.test.ts +0 -45
  3. package/src/__tests__/docker-templates.test.ts +0 -134
  4. package/src/__tests__/go-structs.test.ts +0 -184
  5. package/src/__tests__/naming.test.ts +0 -48
  6. package/src/__tests__/python-dataclasses.test.ts +0 -185
  7. package/src/__tests__/rust-structs.test.ts +0 -176
  8. package/src/__tests__/tags-helpers.test.ts +0 -72
  9. package/src/__tests__/type-mapping.test.ts +0 -332
  10. package/src/__tests__/typescript.test.ts +0 -202
  11. package/src/cobol-copybook/test/.gitignore +0 -6
  12. package/src/cobol-copybook/test/Dockerfile +0 -7
  13. package/src/csharp-records/test/.gitignore +0 -6
  14. package/src/csharp-records/test/Dockerfile +0 -6
  15. package/src/diesel/test/.gitignore +0 -6
  16. package/src/diesel/test/Dockerfile +0 -16
  17. package/src/drizzle/test/.gitignore +0 -6
  18. package/src/drizzle/test/Dockerfile +0 -8
  19. package/src/drizzle/test/test.ts +0 -71
  20. package/src/efcore/test/.gitignore +0 -6
  21. package/src/efcore/test/Dockerfile +0 -7
  22. package/src/go-structs/test/.gitignore +0 -6
  23. package/src/go-structs/test/Dockerfile +0 -13
  24. package/src/go-structs/test/test.go +0 -71
  25. package/src/gorm/test/.gitignore +0 -6
  26. package/src/gorm/test/Dockerfile +0 -13
  27. package/src/gorm/test/test.go +0 -65
  28. package/src/java-records/test/.gitignore +0 -6
  29. package/src/java-records/test/Dockerfile +0 -11
  30. package/src/java-records/test/Test.java +0 -93
  31. package/src/jpa/test/.gitignore +0 -6
  32. package/src/jpa/test/Dockerfile +0 -14
  33. package/src/jpa/test/Test.java +0 -111
  34. package/src/json-schema/test/.gitignore +0 -6
  35. package/src/json-schema/test/Dockerfile +0 -18
  36. package/src/knex/test/.gitignore +0 -6
  37. package/src/knex/test/Dockerfile +0 -7
  38. package/src/knex/test/test.ts +0 -75
  39. package/src/kotlin-data/test/.gitignore +0 -6
  40. package/src/kotlin-data/test/Dockerfile +0 -14
  41. package/src/kotlin-data/test/Test.kt +0 -82
  42. package/src/kysely/test/.gitignore +0 -6
  43. package/src/kysely/test/Dockerfile +0 -8
  44. package/src/kysely/test/test.ts +0 -82
  45. package/src/prisma/test/.gitignore +0 -6
  46. package/src/prisma/test/Dockerfile +0 -7
  47. package/src/protobuf/test/.gitignore +0 -6
  48. package/src/protobuf/test/Dockerfile +0 -6
  49. package/src/pydantic/test/.gitignore +0 -6
  50. package/src/pydantic/test/Dockerfile +0 -8
  51. package/src/pydantic/test/test.py +0 -63
  52. package/src/python-dataclasses/test/.gitignore +0 -6
  53. package/src/python-dataclasses/test/Dockerfile +0 -8
  54. package/src/python-dataclasses/test/test.py +0 -63
  55. package/src/rust-structs/test/.gitignore +0 -6
  56. package/src/rust-structs/test/Dockerfile +0 -22
  57. package/src/rust-structs/test/test.rs +0 -82
  58. package/src/sqlalchemy/test/.gitignore +0 -6
  59. package/src/sqlalchemy/test/Dockerfile +0 -8
  60. package/src/sqlalchemy/test/test.py +0 -61
  61. package/src/sqlc/test/.gitignore +0 -6
  62. package/src/sqlc/test/Dockerfile +0 -13
  63. package/src/sqlc/test/test.go +0 -91
  64. package/src/typescript/test/.gitignore +0 -6
  65. package/src/typescript/test/Dockerfile +0 -8
  66. package/src/typescript/test/test.ts +0 -89
  67. package/src/xsd/test/.gitignore +0 -6
  68. package/src/xsd/test/Dockerfile +0 -6
  69. package/src/zod/test/.gitignore +0 -6
  70. package/src/zod/test/Dockerfile +0 -6
@@ -1,22 +0,0 @@
1
- FROM rust:1.85-slim
2
- RUN apt-get update && apt-get install -y pkg-config libssl-dev && rm -rf /var/lib/apt/lists/*
3
- WORKDIR /app
4
- RUN cargo init --name typecheck .
5
- RUN cat >> Cargo.toml <<'TOML'
6
- serde = { version = "1", features = ["derive"] }
7
- serde_json = "1"
8
- chrono = { version = "0.4", features = ["serde"] }
9
- uuid = { version = "1", features = ["serde"] }
10
- bigdecimal = { version = "0.4", features = ["serde"] }
11
- tokio = { version = "1", features = ["full"] }
12
- tokio-postgres = "0.7"
13
- TOML
14
- RUN rm src/main.rs
15
- COPY models.rs src/models.rs
16
- COPY test.rs src/main.rs
17
- # Prepend mod declaration to main.rs
18
- RUN sed -i '1s/^/mod models;\n/' src/main.rs
19
- # Step 1: compile (typechecks models + test)
20
- RUN cargo build --release
21
- # Step 2: run integration test against real DB
22
- CMD ["./target/release/typecheck"]
@@ -1,82 +0,0 @@
1
- // Integration test for @sqldoc/templates/rust-structs
2
- // Connects to real Postgres, verifies generated structs work with actual data.
3
- //
4
- // Note: `mod models;` is prepended by the Dockerfile.
5
-
6
- use models::{Users, Posts};
7
-
8
- use std::sync::atomic::{AtomicUsize, Ordering};
9
-
10
- static FAILED: AtomicUsize = AtomicUsize::new(0);
11
-
12
- fn assert_eq_val<T: PartialEq + std::fmt::Debug>(actual: T, expected: T, msg: &str) {
13
- if actual != expected {
14
- eprintln!("FAIL: {} (got {:?}, expected {:?})", msg, actual, expected);
15
- FAILED.fetch_add(1, Ordering::SeqCst);
16
- } else {
17
- println!(" ok: {}", msg);
18
- }
19
- }
20
-
21
- #[tokio::main]
22
- async fn main() -> Result<(), Box<dyn std::error::Error>> {
23
- let db_url = std::env::var("DATABASE_URL").expect("DATABASE_URL not set");
24
-
25
- let (client, connection) = tokio_postgres::connect(&db_url, tokio_postgres::NoTls).await?;
26
-
27
- tokio::spawn(async move {
28
- if let Err(e) = connection.await {
29
- eprintln!("connection error: {}", e);
30
- }
31
- });
32
-
33
- println!("--- rust-structs integration test ---");
34
-
35
- // 1. Query user and populate generated struct
36
- let row = client
37
- .query_one("SELECT id, email, name, age, is_active FROM users WHERE id = 1", &[])
38
- .await?;
39
- let user = Users {
40
- id: row.get("id"),
41
- email: row.get("email"),
42
- name: row.get("name"),
43
- age: row.get("age"),
44
- is_active: row.get("is_active"),
45
- metadata: None,
46
- address: None,
47
- created_at: chrono::Utc::now(),
48
- tags: None,
49
- avatar: None,
50
- balance: None,
51
- external_id: None,
52
- };
53
- assert_eq_val(user.email.as_str(), "test@example.com", "user.email matches");
54
- assert_eq_val(user.name, Some("Test User".to_string()), "user.name matches");
55
- assert_eq_val(user.age, Some(30), "user.age matches");
56
- assert_eq_val(user.is_active, true, "user.is_active matches");
57
-
58
- // 2. Query post and populate generated struct
59
- let row = client
60
- .query_one("SELECT id, user_id, title, body, view_count FROM posts WHERE id = 1", &[])
61
- .await?;
62
- let post = Posts {
63
- id: row.get("id"),
64
- user_id: row.get("user_id"),
65
- title: row.get("title"),
66
- body: row.get("body"),
67
- published_at: None,
68
- view_count: row.get("view_count"),
69
- rating: None,
70
- };
71
- assert_eq_val(post.title.as_str(), "Hello World", "post.title matches");
72
- assert_eq_val(post.user_id, 1i64, "post.user_id matches");
73
- assert_eq_val(post.view_count, 42i32, "post.view_count matches");
74
-
75
- let fail_count = FAILED.load(Ordering::SeqCst);
76
- if fail_count > 0 {
77
- eprintln!("\n{} assertion(s) failed", fail_count);
78
- std::process::exit(1);
79
- }
80
- println!("\nAll assertions passed!");
81
- Ok(())
82
- }
@@ -1,6 +0,0 @@
1
- # Generated by codegen — only Dockerfile and test scripts are tracked
2
- *
3
- !.gitignore
4
- !Dockerfile
5
- !test.*
6
- !Test.*
@@ -1,8 +0,0 @@
1
- FROM python:3.13-slim
2
- WORKDIR /app
3
- COPY . .
4
- RUN pip install sqlalchemy psycopg2-binary
5
- # Step 1: syntax check the generated models
6
- RUN python -m py_compile models.py
7
- # Step 2: run integration test against real DB
8
- CMD ["python", "test.py"]
@@ -1,61 +0,0 @@
1
- """
2
- Integration test for @sqldoc/templates/sqlalchemy
3
- Connects to real Postgres, verifies generated SQLAlchemy models work with actual data.
4
- """
5
- import os
6
- import sys
7
-
8
- from sqlalchemy import create_engine, select
9
- from sqlalchemy.orm import Session
10
-
11
- import models
12
-
13
- DATABASE_URL = os.environ.get("DATABASE_URL")
14
- if not DATABASE_URL:
15
- print("DATABASE_URL not set", file=sys.stderr)
16
- sys.exit(1)
17
-
18
- failed = 0
19
-
20
-
21
- def assert_eq(actual, expected, msg):
22
- global failed
23
- if actual != expected:
24
- print(f"FAIL: {msg} (got {actual!r}, expected {expected!r})", file=sys.stderr)
25
- failed += 1
26
- else:
27
- print(f" ok: {msg}")
28
-
29
-
30
- def main():
31
- global failed
32
- engine = create_engine(DATABASE_URL)
33
-
34
- print("--- sqlalchemy integration test ---")
35
-
36
- with Session(engine) as session:
37
- # 1. Query known seeded user via ORM model
38
- user = session.query(models.Users).filter_by(id=1).one()
39
- assert_eq(user.email, "test@example.com", "user email matches")
40
- assert_eq(user.name, "Test User", "user name matches")
41
- assert_eq(user.age, 30, "user age matches")
42
- assert_eq(user.is_active, True, "user is_active matches")
43
-
44
- # 2. Query known seeded post via ORM model
45
- post = session.query(models.Posts).filter_by(id=1).one()
46
- assert_eq(post.title, "Hello World", "post title matches")
47
-
48
- # 3. Query view via Table object
49
- rows = session.execute(select(models.active_users)).fetchall()
50
- assert_eq(len(rows) >= 1, True, "active_users view returns rows")
51
- row = rows[0]
52
- assert_eq(row.email, "test@example.com", "view email matches")
53
-
54
- if failed > 0:
55
- print(f"\n{failed} assertion(s) failed", file=sys.stderr)
56
- sys.exit(1)
57
- print("\nAll assertions passed!")
58
-
59
-
60
- if __name__ == "__main__":
61
- main()
@@ -1,6 +0,0 @@
1
- # Generated by codegen — only Dockerfile and test scripts are tracked
2
- *
3
- !.gitignore
4
- !Dockerfile
5
- !test.*
6
- !Test.*
@@ -1,13 +0,0 @@
1
- FROM golang:1.24-alpine
2
- WORKDIR /app
3
- # Set up Go module with models as a sub-package
4
- RUN go mod init sqldoc-test
5
- RUN mkdir -p models cmd/test
6
- COPY models.go models/
7
- COPY test.go cmd/test/main.go
8
- ENV GOTOOLCHAIN=auto
9
- RUN go get github.com/jackc/pgx/v5 && go mod tidy
10
- # Step 1: typecheck/compile all packages
11
- RUN go build -o /usr/local/bin/test-runner ./cmd/test
12
- # Step 2: run integration test against real DB
13
- CMD ["test-runner"]
@@ -1,91 +0,0 @@
1
- package main
2
-
3
- import (
4
- "context"
5
- "fmt"
6
- "os"
7
-
8
- "github.com/jackc/pgx/v5"
9
-
10
- // Import the generated models to verify they compile
11
- _ "sqldoc-test/models"
12
- )
13
-
14
- var failed int
15
-
16
- func assert(condition bool, msg string) {
17
- if !condition {
18
- fmt.Fprintf(os.Stderr, "FAIL: %s\n", msg)
19
- failed++
20
- } else {
21
- fmt.Printf(" ok: %s\n", msg)
22
- }
23
- }
24
-
25
- func main() {
26
- ctx := context.Background()
27
- dbURL := os.Getenv("DATABASE_URL")
28
- if dbURL == "" {
29
- fmt.Fprintln(os.Stderr, "DATABASE_URL not set")
30
- os.Exit(1)
31
- }
32
-
33
- conn, err := pgx.Connect(ctx, dbURL)
34
- if err != nil {
35
- fmt.Fprintf(os.Stderr, "connect error: %v\n", err)
36
- os.Exit(1)
37
- }
38
- defer conn.Close(ctx)
39
-
40
- fmt.Println("--- sqlc integration test ---")
41
-
42
- // 1. Query known seeded user
43
- var email, name string
44
- var age int32
45
- var isActive bool
46
- err = conn.QueryRow(ctx, "SELECT email, name, age, is_active FROM users WHERE id = 1").
47
- Scan(&email, &name, &age, &isActive)
48
- if err != nil {
49
- fmt.Fprintf(os.Stderr, "query user error: %v\n", err)
50
- os.Exit(1)
51
- }
52
- assert(email == "test@example.com", "user email matches")
53
- assert(name == "Test User", "user name matches")
54
- assert(age == 30, "user age matches")
55
- assert(isActive, "user is_active matches")
56
-
57
- // 2. Query known seeded post
58
- var title string
59
- err = conn.QueryRow(ctx, "SELECT title FROM posts WHERE id = 1").Scan(&title)
60
- if err != nil {
61
- fmt.Fprintf(os.Stderr, "query post error: %v\n", err)
62
- os.Exit(1)
63
- }
64
- assert(title == "Hello World", "post title matches")
65
-
66
- // 3. Insert a new post
67
- _, err = conn.Exec(ctx,
68
- "INSERT INTO posts (user_id, title, body, view_count) VALUES (1, 'Post from sqlc', 'test body', 0)")
69
- if err != nil {
70
- fmt.Fprintf(os.Stderr, "insert error: %v\n", err)
71
- os.Exit(1)
72
- }
73
-
74
- // 4. Read it back
75
- var newTitle string
76
- var userID int64
77
- err = conn.QueryRow(ctx, "SELECT title, user_id FROM posts WHERE title = 'Post from sqlc'").
78
- Scan(&newTitle, &userID)
79
- if err != nil {
80
- fmt.Fprintf(os.Stderr, "read back error: %v\n", err)
81
- os.Exit(1)
82
- }
83
- assert(newTitle == "Post from sqlc", "inserted post title matches")
84
- assert(userID == 1, "inserted post user_id matches")
85
-
86
- if failed > 0 {
87
- fmt.Fprintf(os.Stderr, "\n%d assertion(s) failed\n", failed)
88
- os.Exit(1)
89
- }
90
- fmt.Println("\nAll assertions passed!")
91
- }
@@ -1,6 +0,0 @@
1
- # Generated by codegen — only Dockerfile and test scripts are tracked
2
- *
3
- !.gitignore
4
- !Dockerfile
5
- !test.*
6
- !Test.*
@@ -1,8 +0,0 @@
1
- FROM node:23-slim
2
- WORKDIR /app
3
- COPY . .
4
- RUN npm init -y && npm pkg set type=module && npm install typescript@5 pg @types/pg @types/node --save-dev
5
- # Step 1: typecheck the generated models
6
- RUN npx tsc --noEmit --strict --esModuleInterop --module nodenext --moduleResolution nodenext models.ts
7
- # Step 2: run integration test against real DB
8
- CMD ["node", "--experimental-strip-types", "test.ts"]
@@ -1,89 +0,0 @@
1
- /**
2
- * Integration test for @sqldoc/templates/typescript
3
- * Connects to real Postgres, verifies generated types work with actual data.
4
- */
5
- import { Client } from 'pg'
6
- // Import the generated type -- file is copied from codegen output at test time
7
- import type { Users, Posts } from './models.ts'
8
-
9
- const DATABASE_URL = process.env.DATABASE_URL
10
- if (!DATABASE_URL) {
11
- console.error('DATABASE_URL not set')
12
- process.exit(1)
13
- }
14
-
15
- const client = new Client(DATABASE_URL)
16
-
17
- let failed = 0
18
- function assert(condition: boolean, msg: string) {
19
- if (!condition) {
20
- console.error(`FAIL: ${msg}`)
21
- failed++
22
- } else {
23
- console.log(` ok: ${msg}`)
24
- }
25
- }
26
-
27
- async function run() {
28
- await client.connect()
29
-
30
- try {
31
- console.log('--- typescript integration test ---')
32
-
33
- // 1. Query known seeded user
34
- const { rows: userRows } = await client.query('SELECT * FROM users WHERE id = 1')
35
- const user = userRows[0]
36
- assert(user.email === 'test@example.com', 'user email matches')
37
- assert(user.name === 'Test User', 'user name matches')
38
- assert(user.age === 30, 'user age matches')
39
- assert(user.is_active === true, 'user is_active matches')
40
-
41
- // Verify the type is assignable (compile-time check; runtime confirms shape)
42
- const _typedUser: Partial<Users> = {
43
- id: Number(user.id),
44
- email: user.email,
45
- name: user.name,
46
- age: user.age,
47
- isActive: user.is_active,
48
- }
49
- assert(typeof _typedUser.email === 'string', 'typed user email is string')
50
-
51
- // 2. Query known seeded post
52
- const { rows: postRows } = await client.query('SELECT * FROM posts WHERE id = 1')
53
- assert(postRows.length === 1, 'seeded post found')
54
- assert(postRows[0].title === 'Hello World', 'post title matches')
55
-
56
- // Verify Posts type assignability
57
- const _typedPost: Partial<Posts> = {
58
- id: Number(postRows[0].id),
59
- title: postRows[0].title,
60
- body: postRows[0].body,
61
- }
62
- assert(typeof _typedPost.title === 'string', 'typed post title is string')
63
-
64
- // 3. Insert a new post
65
- await client.query(
66
- "INSERT INTO posts (user_id, title, body, view_count) VALUES (1, 'Post from typescript', 'test body', 0)",
67
- )
68
-
69
- // 4. Read it back
70
- const { rows: newPosts } = await client.query("SELECT * FROM posts WHERE title = 'Post from typescript'")
71
- assert(newPosts.length === 1, 'inserted post found')
72
- assert(newPosts[0].title === 'Post from typescript', 'inserted post title matches')
73
- // pg returns bigint columns as strings; use Number() for comparison
74
- assert(Number(newPosts[0].user_id) === 1, 'inserted post user_id matches')
75
-
76
- if (failed > 0) {
77
- console.error(`\n${failed} assertion(s) failed`)
78
- process.exit(1)
79
- }
80
- console.log('\nAll assertions passed!')
81
- } finally {
82
- await client.end()
83
- }
84
- }
85
-
86
- run().catch((err) => {
87
- console.error(err)
88
- process.exit(1)
89
- })
@@ -1,6 +0,0 @@
1
- # Generated by codegen — only Dockerfile and test scripts are tracked
2
- *
3
- !.gitignore
4
- !Dockerfile
5
- !test.*
6
- !Test.*
@@ -1,6 +0,0 @@
1
- FROM alpine:3.20
2
- RUN apk add --no-cache libxml2-utils
3
- WORKDIR /app
4
- COPY . .
5
- RUN xmllint --noout schema.xsd
6
- CMD ["echo", "ok"]
@@ -1,6 +0,0 @@
1
- # Generated by codegen — only Dockerfile and test scripts are tracked
2
- *
3
- !.gitignore
4
- !Dockerfile
5
- !test.*
6
- !Test.*
@@ -1,6 +0,0 @@
1
- FROM node:23-slim
2
- WORKDIR /app
3
- COPY . .
4
- RUN npm init -y && npm install typescript@5 zod@3 @types/node --save-dev
5
- RUN npx tsc --noEmit --strict --esModuleInterop --module nodenext --moduleResolution nodenext *.ts
6
- CMD ["echo", "ok"]