Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: do not export queries #49

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions examples/bun-mysql2/src/db/query_sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import mysql, { RowDataPacket, ResultSetHeader } from "mysql2/promise";

type Client = mysql.Connection | mysql.Pool;

export const getAuthorQuery = `-- name: GetAuthor :one
const getAuthorQuery = `-- name: GetAuthor :one
SELECT id, name, bio FROM authors
WHERE id = ? LIMIT 1`;

Expand Down Expand Up @@ -35,7 +35,7 @@ export async function getAuthor(client: Client, args: GetAuthorArgs): Promise<Ge
};
}

export const listAuthorsQuery = `-- name: ListAuthors :many
const listAuthorsQuery = `-- name: ListAuthors :many
SELECT id, name, bio FROM authors
ORDER BY name`;

Expand All @@ -60,7 +60,7 @@ export async function listAuthors(client: Client): Promise<ListAuthorsRow[]> {
});
}

export const createAuthorQuery = `-- name: CreateAuthor :exec
const createAuthorQuery = `-- name: CreateAuthor :exec
INSERT INTO authors (
name, bio
) VALUES (
Expand All @@ -79,7 +79,7 @@ export async function createAuthor(client: Client, args: CreateAuthorArgs): Prom
});
}

export const createAuthorReturnIdQuery = `-- name: CreateAuthorReturnId :execlastid
const createAuthorReturnIdQuery = `-- name: CreateAuthorReturnId :execlastid
INSERT INTO authors (
name, bio
) VALUES (
Expand All @@ -99,7 +99,7 @@ export async function createAuthorReturnId(client: Client, args: CreateAuthorRet
return result?.insertId ?? 0;
}

export const deleteAuthorQuery = `-- name: DeleteAuthor :exec
const deleteAuthorQuery = `-- name: DeleteAuthor :exec
DELETE FROM authors
WHERE id = ?`;

Expand All @@ -114,7 +114,7 @@ export async function deleteAuthor(client: Client, args: DeleteAuthorArgs): Prom
});
}

export const testQuery = `-- name: Test :one
const testQuery = `-- name: Test :one
SELECT c_bit, c_tinyint, c_bool, c_boolean, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_serial, c_decimal, c_dec, c_numeric, c_fixed, c_float, c_double, c_double_precision, c_date, c_time, c_datetime, c_timestamp, c_year, c_char, c_nchar, c_national_char, c_varchar, c_binary, c_varbinary, c_tinyblob, c_tinytext, c_blob, c_text, c_mediumblob, c_mediumtext, c_longblob, c_longtext, c_json FROM node_mysql_types
LIMIT 1`;

Expand Down
8 changes: 4 additions & 4 deletions examples/bun-pg/src/db/query_sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface Client {
query: (config: QueryArrayConfig) => Promise<QueryArrayResult>;
}

export const getAuthorQuery = `-- name: GetAuthor :one
const getAuthorQuery = `-- name: GetAuthor :one
SELECT id, name, bio FROM authors
WHERE id = $1 LIMIT 1`;

Expand Down Expand Up @@ -37,7 +37,7 @@ export async function getAuthor(client: Client, args: GetAuthorArgs): Promise<Ge
};
}

export const listAuthorsQuery = `-- name: ListAuthors :many
const listAuthorsQuery = `-- name: ListAuthors :many
SELECT id, name, bio FROM authors
ORDER BY name`;

Expand All @@ -62,7 +62,7 @@ export async function listAuthors(client: Client): Promise<ListAuthorsRow[]> {
});
}

export const createAuthorQuery = `-- name: CreateAuthor :one
const createAuthorQuery = `-- name: CreateAuthor :one
INSERT INTO authors (
name, bio
) VALUES (
Expand Down Expand Up @@ -98,7 +98,7 @@ export async function createAuthor(client: Client, args: CreateAuthorArgs): Prom
};
}

export const deleteAuthorQuery = `-- name: DeleteAuthor :exec
const deleteAuthorQuery = `-- name: DeleteAuthor :exec
DELETE FROM authors
WHERE id = $1`;

Expand Down
8 changes: 4 additions & 4 deletions examples/bun-postgres/src/db/query_sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { Sql } from "postgres";

export const getAuthorQuery = `-- name: GetAuthor :one
const getAuthorQuery = `-- name: GetAuthor :one
SELECT id, name, bio FROM authors
WHERE id = $1 LIMIT 1`;

Expand Down Expand Up @@ -32,7 +32,7 @@ export async function getAuthor(sql: Sql, args: GetAuthorArgs): Promise<GetAutho
};
}

export const listAuthorsQuery = `-- name: ListAuthors :many
const listAuthorsQuery = `-- name: ListAuthors :many
SELECT id, name, bio FROM authors
ORDER BY name`;

Expand All @@ -50,7 +50,7 @@ export async function listAuthors(sql: Sql): Promise<ListAuthorsRow[]> {
}));
}

export const createAuthorQuery = `-- name: CreateAuthor :one
const createAuthorQuery = `-- name: CreateAuthor :one
INSERT INTO authors (
name, bio
) VALUES (
Expand Down Expand Up @@ -85,7 +85,7 @@ export async function createAuthor(sql: Sql, args: CreateAuthorArgs): Promise<Cr
};
}

export const deleteAuthorQuery = `-- name: DeleteAuthor :exec
const deleteAuthorQuery = `-- name: DeleteAuthor :exec
DELETE FROM authors
WHERE id = $1`;

Expand Down
8 changes: 4 additions & 4 deletions examples/node-better-sqlite3/src/db/query_sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { Database } from "better-sqlite3";

export const getAuthorQuery = `-- name: GetAuthor :one
const getAuthorQuery = `-- name: GetAuthor :one
SELECT id, name, bio FROM authors
WHERE id = ? LIMIT 1`;

Expand All @@ -25,7 +25,7 @@ export async function getAuthor(database: Database, args: GetAuthorArgs): Promis
return result as GetAuthorRow;
}

export const listAuthorsQuery = `-- name: ListAuthors :many
const listAuthorsQuery = `-- name: ListAuthors :many
SELECT id, name, bio FROM authors
ORDER BY name`;

Expand All @@ -41,7 +41,7 @@ export async function listAuthors(database: Database): Promise<ListAuthorsRow[]>
return result as ListAuthorsRow[];
}

export const createAuthorQuery = `-- name: CreateAuthor :exec
const createAuthorQuery = `-- name: CreateAuthor :exec
INSERT INTO authors (
name, bio
) VALUES (
Expand All @@ -58,7 +58,7 @@ export async function createAuthor(database: Database, args: CreateAuthorArgs):
await stmt.run(args.name, args.bio);
}

export const deleteAuthorQuery = `-- name: DeleteAuthor :exec
const deleteAuthorQuery = `-- name: DeleteAuthor :exec
DELETE FROM authors
WHERE id = ?`;

Expand Down
12 changes: 6 additions & 6 deletions examples/node-mysql2/src/db/query_sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import mysql, { RowDataPacket, ResultSetHeader } from "mysql2/promise";

type Client = mysql.Connection | mysql.Pool;

export const getAuthorQuery = `-- name: GetAuthor :one
const getAuthorQuery = `-- name: GetAuthor :one
SELECT id, name, bio FROM authors
WHERE id = ? LIMIT 1`;

Expand Down Expand Up @@ -35,7 +35,7 @@ export async function getAuthor(client: Client, args: GetAuthorArgs): Promise<Ge
};
}

export const listAuthorsQuery = `-- name: ListAuthors :many
const listAuthorsQuery = `-- name: ListAuthors :many
SELECT id, name, bio FROM authors
ORDER BY name`;

Expand All @@ -60,7 +60,7 @@ export async function listAuthors(client: Client): Promise<ListAuthorsRow[]> {
});
}

export const createAuthorQuery = `-- name: CreateAuthor :exec
const createAuthorQuery = `-- name: CreateAuthor :exec
INSERT INTO authors (
name, bio
) VALUES (
Expand All @@ -79,7 +79,7 @@ export async function createAuthor(client: Client, args: CreateAuthorArgs): Prom
});
}

export const createAuthorReturnIdQuery = `-- name: CreateAuthorReturnId :execlastid
const createAuthorReturnIdQuery = `-- name: CreateAuthorReturnId :execlastid
INSERT INTO authors (
name, bio
) VALUES (
Expand All @@ -99,7 +99,7 @@ export async function createAuthorReturnId(client: Client, args: CreateAuthorRet
return result?.insertId ?? 0;
}

export const deleteAuthorQuery = `-- name: DeleteAuthor :exec
const deleteAuthorQuery = `-- name: DeleteAuthor :exec
DELETE FROM authors
WHERE id = ?`;

Expand All @@ -114,7 +114,7 @@ export async function deleteAuthor(client: Client, args: DeleteAuthorArgs): Prom
});
}

export const testQuery = `-- name: Test :one
const testQuery = `-- name: Test :one
SELECT c_bit, c_tinyint, c_bool, c_boolean, c_smallint, c_mediumint, c_int, c_integer, c_bigint, c_serial, c_decimal, c_dec, c_numeric, c_fixed, c_float, c_double, c_double_precision, c_date, c_time, c_datetime, c_timestamp, c_year, c_char, c_nchar, c_national_char, c_varchar, c_binary, c_varbinary, c_tinyblob, c_tinytext, c_blob, c_text, c_mediumblob, c_mediumtext, c_longblob, c_longtext, c_json FROM node_mysql_types
LIMIT 1`;

Expand Down
8 changes: 4 additions & 4 deletions examples/node-pg/src/db/query_sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface Client {
query: (config: QueryArrayConfig) => Promise<QueryArrayResult>;
}

export const getAuthorQuery = `-- name: GetAuthor :one
const getAuthorQuery = `-- name: GetAuthor :one
SELECT id, name, bio FROM authors
WHERE id = $1 LIMIT 1`;

Expand Down Expand Up @@ -37,7 +37,7 @@ export async function getAuthor(client: Client, args: GetAuthorArgs): Promise<Ge
};
}

export const listAuthorsQuery = `-- name: ListAuthors :many
const listAuthorsQuery = `-- name: ListAuthors :many
SELECT id, name, bio FROM authors
ORDER BY name`;

Expand All @@ -62,7 +62,7 @@ export async function listAuthors(client: Client): Promise<ListAuthorsRow[]> {
});
}

export const createAuthorQuery = `-- name: CreateAuthor :one
const createAuthorQuery = `-- name: CreateAuthor :one
INSERT INTO authors (
name, bio
) VALUES (
Expand Down Expand Up @@ -98,7 +98,7 @@ export async function createAuthor(client: Client, args: CreateAuthorArgs): Prom
};
}

export const deleteAuthorQuery = `-- name: DeleteAuthor :exec
const deleteAuthorQuery = `-- name: DeleteAuthor :exec
DELETE FROM authors
WHERE id = $1`;

Expand Down
8 changes: 4 additions & 4 deletions examples/node-postgres/src/db/query_sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { Sql } from "postgres";

export const getAuthorQuery = `-- name: GetAuthor :one
const getAuthorQuery = `-- name: GetAuthor :one
SELECT id, name, bio FROM authors
WHERE id = $1 LIMIT 1`;

Expand Down Expand Up @@ -32,7 +32,7 @@ export async function getAuthor(sql: Sql, args: GetAuthorArgs): Promise<GetAutho
};
}

export const listAuthorsQuery = `-- name: ListAuthors :many
const listAuthorsQuery = `-- name: ListAuthors :many
SELECT id, name, bio FROM authors
ORDER BY name`;

Expand All @@ -50,7 +50,7 @@ export async function listAuthors(sql: Sql): Promise<ListAuthorsRow[]> {
}));
}

export const createAuthorQuery = `-- name: CreateAuthor :one
const createAuthorQuery = `-- name: CreateAuthor :one
INSERT INTO authors (
name, bio
) VALUES (
Expand Down Expand Up @@ -85,7 +85,7 @@ export async function createAuthor(sql: Sql, args: CreateAuthorArgs): Promise<Cr
};
}

export const deleteAuthorQuery = `-- name: DeleteAuthor :exec
const deleteAuthorQuery = `-- name: DeleteAuthor :exec
DELETE FROM authors
WHERE id = $1`;

Expand Down
3 changes: 1 addition & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import { readFileSync, writeFileSync, STDIO } from "javy/fs";
import {
EmitHint,
FunctionDeclaration,
NewLineKind,
TypeNode,
ScriptKind,
Expand Down Expand Up @@ -222,7 +221,7 @@ function readInput(): GenerateRequest {

function queryDecl(name: string, sql: string) {
return factory.createVariableStatement(
[factory.createToken(SyntaxKind.ExportKeyword)],
[],
factory.createVariableDeclarationList(
[
factory.createVariableDeclaration(
Expand Down