Skip to content

Query params only detected properly if parameter comes after condition #266

@Nydauron

Description

@Nydauron

The following query generates to the following types:

import { sql } from "sqlx-ts";

export const bannerQuery = sql`
SELECT background_color, text_color, link, message, end FROM announcements WHERE publish = 1 AND ? >= begin AND end >= ?`;
export type BannerQueryParams = [boolean, Date];

export interface IBannerQueryResult {
	background_color: string;
	end: Date;
	link: string | null;
	message: string | null;
	text_color: string;
}

export interface IBannerQueryQuery {
	params: BannerQueryParams;
	result: IBannerQueryResult;
}

The expected codegen should be:

export type BannerQueryParams = [Date, Date];

export interface IBannerQueryResult {
	background_color: string;
	end: Date;
	link: string | null;
	message: string | null;
	text_color: string;
}

export interface IBannerQueryQuery {
	params: BannerQueryParams;
	result: IBannerQueryResult;
}

Likely semi-related to the same issue, but another example is the following query:

import { sql } from "sqlx-ts";

export const bannerQuery = sql`
SELECT background_color, text_color, link, message, end FROM announcements WHERE publish = 1 AND ? BETWEEN begin AND end`;

This query generates to:

export type BannerQueryParams = [];

export interface IBannerQueryResult {
	background_color: string;
	end: Date;
	link: string | null;
	message: string | null;
	text_color: string;
}

export interface IBannerQueryQuery {
	params: BannerQueryParams;
	result: IBannerQueryResult;
}

When it should generate to:

```ts
export type BannerQueryParams = [Date];

export interface IBannerQueryResult {
	background_color: string;
	end: Date;
	link: string | null;
	message: string | null;
	text_color: string;
}

export interface IBannerQueryQuery {
	params: BannerQueryParams;
	result: IBannerQueryResult;
}

but this can be a lack of support for the BETWEEN clause.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions