From a9391cd383a68bdb42749e71737ba14195415647 Mon Sep 17 00:00:00 2001 From: Ryan Rasti Date: Mon, 17 Nov 2025 21:07:37 -0800 Subject: [PATCH] fix ci --- README.md | 4 ++-- examples/schema.ts | 16 ++++++++-------- src/escape-literal.ts | 34 ++++++++++++++++++++++++++++++++++ src/expression.ts | 2 +- 4 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 src/escape-literal.ts diff --git a/README.md b/README.md index 963957e0..cc90a9a0 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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; diff --git a/examples/schema.ts b/examples/schema.ts index a4632a02..498713d6 100644 --- a/examples/schema.ts +++ b/examples/schema.ts @@ -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 diff --git a/src/escape-literal.ts b/src/escape-literal.ts new file mode 100644 index 00000000..3ce3268e --- /dev/null +++ b/src/escape-literal.ts @@ -0,0 +1,34 @@ +// Taken from:https://github.com/brianc/node-postgres/blob/8d493f3b5531bfe226d40c1d64d1d020ee33fd6f/packages/pg/lib/utils.js#L175 + +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; + } + + return escaped; +}; diff --git a/src/expression.ts b/src/expression.ts index d5a825af..05f5c056 100644 --- a/src/expression.ts +++ b/src/expression.ts @@ -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) {}