Skip to content
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Typegres: SQL-over-RPC, Safely

[![npm version](https://img.shields.io/npm/v/typegres.svg)](https://www.npmjs.com/package/typegres) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
[![CI](https://github.com/ryanrasti/typegres/actions/workflows/main.yml/badge.svg)](https://github.com/ryanrasti/typegres/actions/workflows/main.yml) [![npm version](https://img.shields.io/npm/v/typegres.svg)](https://www.npmjs.com/package/typegres) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)

A TypeScript API framework that lets clients compose any queries they need within boundaries you control.

Expand All @@ -16,7 +16,7 @@ export class User extends Models.User {
// Your public interface stays stable as your schema evolves
createdAt() {
// Before: accessing from JSONB metadata
// return this.metadata['->>'](createdAt).cast(Timestamptz);
// return this.metadata['->>']('createdAt').cast(Timestamptz);

// After: direct column access (schema refactored)
return this.created_at;
Expand Down
16 changes: 8 additions & 8 deletions examples/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { Typegres, Text, Int4, Bool, Table } from "typegres";

// Define the database schema using the new Table pattern
export class Users extends Table("users", {
id: Int4<1>,
name: Text<1>,
age: Int4<1>,
isActive: Bool<1>,
id: { type: Int4<1>, required: false },
name: { type: Text<1>, required: true },
age: { type: Int4<1>, required: true },
isActive: { type: Bool<1>, required: true },
}) {}

export class Posts extends Table("posts", {
id: Int4<1>,
author_id: Int4<1>,
title: Text<1>,
created_at: Text<1>, // Treating timestamp as text for simplicity
id: { type: Int4<1>, required: false },
author_id: { type: Int4<1>, required: true },
title: { type: Text<1>, required: true },
created_at: { type: Text<1>, required: true }, // Treating timestamp as text for simplicity
}) {}

// Create tables using raw SQL
Expand Down
34 changes: 34 additions & 0 deletions src/escape-literal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Taken from:https://github.com/brianc/node-postgres/blob/8d493f3b5531bfe226d40c1d64d1d020ee33fd6f/packages/pg/lib/utils.js#L175

Copilot AI Nov 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after colon in the URL comment. Should be "Taken from: https://..." instead of "Taken from:https://..."

Suggested change
// Taken from:https://github.com/brianc/node-postgres/blob/8d493f3b5531bfe226d40c1d64d1d020ee33fd6f/packages/pg/lib/utils.js#L175
// Taken from: https://github.com/brianc/node-postgres/blob/8d493f3b5531bfe226d40c1d64d1d020ee33fd6f/packages/pg/lib/utils.js#L175

Copilot uses AI. Check for mistakes.

export const escapeLiteral = function (str: string) {
let hasBackslash = false;
let escaped = "'";

if (str == null) {
return "''";
}

if (typeof str !== "string") {
return "''";
}

for (let i = 0; i < str.length; i++) {
const c = str[i];
if (c === "'") {
escaped += c + c;
} else if (c === "\\") {
escaped += c + c;
hasBackslash = true;
} else {
escaped += c;
}
}

escaped += "'";

if (hasBackslash === true) {
escaped = " E" + escaped;

Copilot AI Nov 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The escaped string should be prefixed with "E" (without a leading space). The current implementation adds " E" with a space, which would result in invalid SQL syntax like " E'...'". This should be "E" + escaped instead of " E" + escaped.

Suggested change
escaped = " E" + escaped;
escaped = "E" + escaped;

Copilot uses AI. Check for mistakes.
}

return escaped;
};
2 changes: 1 addition & 1 deletion src/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { RowLike } from "./query/values";
import type { Any } from "./types";
import type { OrderBySpec } from "./query/order-by";
import { compileOrderBy } from "./query/order-by";
import { escapeLiteral } from "pg";
import { escapeLiteral } from "./escape-literal";

export class QueryAlias {
constructor(public name: string) {}
Expand Down