ehmpathy / sql-code-generator

Generate code from your SQL schema and queries for type safety and development speed.
MIT License
28 stars 3 forks source link

specifying SQL query in .sql files works, but same query in .ts file fails #81

Open BoilerTom90 opened 1 year ago

BoilerTom90 commented 1 year ago

I have the same query that I've specified in an SQL file, and code gen properly processes it. But, when I move that query to a .ts file, so that I can actually use it in TS program, it fails with the same error that it gives for all failures.

The query in the SQL file that that works is:

-- query_name = allRunners
SELECT runners.id,
   runners.firstName,
   runners.lastName,
   runners.sex,
   runners.grade,
   runners.schoolId,
   runners.raceId,
   meets.id as meetsId
FROM runners as runners
   LEFT JOIN races as races ON races.id = runners.raceId
   LEFT JOIN meets as meets ON meetsId = races.meetId
ORDER BY meetsId,
   races.id,
   runners.schoolId,
   runners.id

The query in the TS file that fails to be parsed is:

export const sql = `
-- query_name = allRunners
SELECT runners.id,
   runners.firstName,
   runners.lastName,
   runners.sex,
   runners. Grade,
   runners.schoolId,
   runners.raceId,
   meets.id as meetsId
FROM runners as runners
   LEFT JOIN races as races ON races.id = runners.raceId
   LEFT JOIN meets as meets ON meetsId = races.meetId
ORDER BY meetsId,
   races.id,
   runners.schoolId,
   runners.id
`;

The error given is simply:

Error: could not extract sql from file at path '...queries/allrunners.ts'
uladkasach commented 1 year ago

Looks like there's a syntax error in the ts file

Mind trying again with that change?