Skip to content

Conversation

Copy link

Copilot AI commented Aug 28, 2025

This PR completes the TypeScript conversion of the PostgreSQL query builder, building upon the draft work in PR #2. The implementation provides full type safety while maintaining complete backward compatibility with existing JavaScript usage.

Key Features

🔧 Complete TypeScript Implementation

All functionality from the original JavaScript version has been ported to TypeScript with proper type annotations:

import QueryBuilder from '@bigbadweb/postgres-query-builder';

const builder = QueryBuilder();
const query = builder
  .select('u.name', 'user_name')
  .from('users', 'u')
  .whereEquals('u.status', 'active')
  .whereIsNotNull('u.email')
  .sql();

📋 Schema-Aware Type Safety (Drizzle-like)

Optional schema definitions provide compile-time type safety for table and column references:

interface MySchema extends SchemaDefinition {
  users: {
    id: 'number';
    email: 'string';
    name: 'string';
    is_active: 'boolean';
  };
}

const builder = QueryBuilder<MySchema>();
// TypeScript will now provide intellisense and type checking for column names

🐛 Bug Fixes

  • Fixed critical bug in page() method where params.push() was called without arguments
  • Fixed MySQL dialect support to properly use ? placeholders instead of $1, $2...
  • Added dynamic dialect detection instead of compile-time constants

📦 Missing Method Implementation

Added several methods that were missing from the draft TypeScript version:

  • whereNull(), whereIsNull(), whereIsNotNull() for NULL checking
  • selectDistinctOn() with groupClause parameter support
  • _selectMulti() for array-based column selection
  • raw_join() for custom join clauses
  • rangeFilterMultiColumn() and betweenColumnValuesMulti() for advanced filtering
  • matchEmpty parameter support in array filtering
  • customResultsFunc parameter in findMany()

🔄 Backward Compatibility

The TypeScript version maintains full compatibility with existing JavaScript codebases:

// Existing JavaScript code continues to work unchanged
const QueryBuilder = require('@bigbadweb/postgres-query-builder');
const builder = QueryBuilder();

🏗️ Build System

  • Complete TypeScript build configuration with declaration file generation
  • Updated package.json with proper TypeScript entry points
  • Automated build process with npm run build
  • Comprehensive test coverage

Migration Guide

For JavaScript Users

No changes required - existing code continues to work without modification.

For TypeScript Users

// Basic usage (no schema)
import QueryBuilder from '@bigbadweb/postgres-query-builder';
const builder = QueryBuilder();

// Schema-aware usage
import QueryBuilder, { SchemaDefinition } from '@bigbadweb/postgres-query-builder';
interface MySchema extends SchemaDefinition { /* your schema */ }
const builder = QueryBuilder<MySchema>();

The implementation now provides a modern, type-safe development experience while preserving all existing functionality and maintaining backward compatibility.

Fixes #3.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link
Author

Copilot AI commented Aug 28, 2025

@mattstabeler 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot AI and others added 2 commits August 28, 2025 06:32
Co-authored-by: mattstabeler <237220+mattstabeler@users.noreply.github.com>
Co-authored-by: mattstabeler <237220+mattstabeler@users.noreply.github.com>
Copilot AI changed the title [WIP] Convert to use typescript Convert to TypeScript with enhanced type safety and schema support Aug 28, 2025
Copilot AI requested a review from mattstabeler August 28, 2025 06:35
@mattstabeler mattstabeler marked this pull request as ready for review August 28, 2025 08:22
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.

Convert to use typescript

2 participants