Skip to content

Conversation

@ryanrasti
Copy link
Owner

No description provided.

@ryanrasti ryanrasti requested a review from Copilot August 25, 2025 19:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements DDL (Data Definition Language) support for PostgreSQL by adding CREATE TABLE functionality. The implementation includes comprehensive column definitions, constraints, and table options following PostgreSQL syntax.

  • Adds DDL Context to Expression system to handle literal values without query parameters
  • Implements comprehensive CREATE TABLE grammar with column constraints and table constraints
  • Updates type system to use new this(v) pattern for proper inheritance

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/types/record.ts Updates compile method to accept Context parameter for DDL support
src/types/bool.ts Adds static new method overloads using inheritance pattern
src/types/any.ts Changes static new method to use new this(v) for proper inheritance
src/grammar/utils.ts Adds Identifier type for SQL injection prevention
src/grammar/create-table.ts Implements complete CREATE TABLE grammar with constraints and options
src/grammar/create-table.test.ts Comprehensive test suite for CREATE TABLE functionality
src/gen/gen.ts Updates code generation to use inheritance pattern and remove type prefixes
src/expression.ts Adds DDL context support and literal escaping for DDL statements

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

import type { OrderBySpec } from "./query/order-by";
import { compileOrderBy } from "./query/order-by";
import { escapeLiteral } from "pg";

Copy link

Copilot AI Aug 25, 2025

Choose a reason for hiding this comment

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

The import of escapeLiteral from the 'pg' package may not be available in all environments or could introduce a dependency that's not needed everywhere. Consider wrapping this in a try-catch or providing a fallback implementation.

Suggested change
// Helper to provide escapeLiteral with fallback if 'pg' is not available
function getEscapeLiteral() {
try {
// Try to require 'pg' dynamically (works in Node.js environments)
// eslint-disable-next-line @typescript-eslint/no-var-requires
return require("pg").escapeLiteral as (str: string) => string;
} catch {
// Fallback: basic SQL literal escaping (not as robust as pg's)
return (str: string) => "'" + str.replace(/'/g, "''") + "'";
}
}
const escapeLiteral = getEscapeLiteral();

Copilot uses AI. Check for mistakes.
class ExtendedType extends (DataType as any) {
static options = [...(combined ? [combined] : []), ...(constraints ?? [])];
}
return ExtendedType.new(new BareColumnExpression("TODO")) as ColumnWithNullability<T, C>;
Copy link

Copilot AI Aug 25, 2025

Choose a reason for hiding this comment

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

The hardcoded "TODO" string suggests incomplete implementation. This should be replaced with a proper value or the TODO should be addressed before merging.

Suggested change
return ExtendedType.new(new BareColumnExpression("TODO")) as ColumnWithNullability<T, C>;
return ExtendedType.new(new BareColumnExpression("")) as ColumnWithNullability<T, C>;

Copilot uses AI. Check for mistakes.

return sql`${sqlJoin(parts, sql` `)} (${sqlJoin(columnDefs)})${afterTable ? sql` ${afterTable}` : sql``}`;
}

Copy link

Copilot AI Aug 25, 2025

Choose a reason for hiding this comment

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

The todo() method throws an error for unimplemented features. Consider either implementing these features or documenting which specific PostgreSQL CREATE TABLE features are intentionally not supported.

Suggested change
/**
* Not implemented: The following PostgreSQL CREATE TABLE features are intentionally not supported:
* - INHERITS
* - PARTITION BY
* - USING (storage method)
* - WITH (storage parameters) / WITHOUT OIDS
* - ON COMMIT
* - TABLESPACE
*
* If you require these features, please open an issue or submit a pull request.
*/

Copilot uses AI. Check for mistakes.
for (const key of Object.keys(instance)) {
const columnDef = instance[key as keyof T];
invariant(isColumn(columnDef), `Property ${key} is not a valid column definition`);
columnDef.v = new BareColumnExpression(key);
Copy link

Copilot AI Aug 25, 2025

Choose a reason for hiding this comment

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

[nitpick] Direct assignment to columnDef.v suggests mutation of an object that may be expected to be immutable. Consider if this side effect is necessary or if there's a more functional approach.

Suggested change
columnDef.v = new BareColumnExpression(key);
instance[key as keyof T] = { ...columnDef, v: new BareColumnExpression(key) };

Copilot uses AI. Check for mistakes.
@ryanrasti ryanrasti force-pushed the ryanrasti/typ-158-ddl-create-table branch 2 times, most recently from a23f8ed to c865686 Compare August 25, 2025 21:25
@ryanrasti ryanrasti force-pushed the ryanrasti/typ-158-ddl-create-table branch from c865686 to 230354c Compare August 25, 2025 21:30
@ryanrasti ryanrasti merged commit 010b4fd into main Aug 25, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants