vlcn-io / typed-sql

MIT License
97 stars 2 forks source link

Ignore quotes and braces and case #31

Open jlarmstrongiv opened 12 months ago

jlarmstrongiv commented 12 months ago

Braces from SQL definition

Ignore braces in column names, as they are in the sql column from the sqlite_schema table:

CREATE TABLE "artists"
(
    [ArtistId] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    [Name] TEXT(120)
);

Quotes in table names

Ignore quotes in the table names:

const query = generatedSchema.sql<{
  GenreId: number;
  Name: string | null
}>`SELECT * FROM "genres"`;

Without quotes, column selection fails:

const query = generatedSchema.sql<{

}>`SELECT * FROM genres`;

Matching case in column and table names

Ignore column and table case in the queries:

  const query = schema.sql<{
  Name: string | null
}>`SELECT Name FROM artists`;

Without matching case, column selection fails:

  const query = schema.sql<{/*
  Could not find selected column name in from clause
*/}>`SELECT name FROM artists`;

Missing Semicolons

Have a user friendly error message when defining schema and forgetting a semicolon or two:

CREATE TABLE "albums"
(
    AlbumId INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    Title TEXT(160)  NOT NULL,
    ArtistId INTEGER  NOT NULL,
    FOREIGN KEY (ArtistId) REFERENCES "artists" (ArtistId)
        ON DELETE NO ACTION ON UPDATE NO ACTION
)

CREATE TABLE sqlite_sequence(name,seq)
tantaman commented 11 months ago

Quotes in table names should be resolved. Working on braces next.

I've also found that I get into a broken state pretty often where no types generate :\

Curious if you've seen that.