gajus / slonik-sql-tag-raw

Slonik SQL tag for constructing dynamic queries.
Other
15 stars 6 forks source link

UnexpectedStateError: Expected token to include "type" property. #18

Closed colinrobertbrooks closed 2 weeks ago

colinrobertbrooks commented 2 years ago

I am attempting to update to slonik-sql-tag-raq v1.1.4 (from v1.1.3) & slonik v28.1.0 (from v27.1.1), but am facing the following error:

UnexpectedStateError: Expected token to include "type" property.
    at isSqlToken (server/node_modules/slonik/src/utilities/isSqlToken.ts:40:11)
    at server/node_modules/slonik-sql-tag-raw/src/utilities/interpolatePositionalParameterReferences.ts:41:19
    at String.replace (<anonymous>)
    at exports.default (server/node_modules/slonik-sql-tag-raw/src/utilities/interpolatePositionalParameterReferences.ts:37:30)
    at exports.default (server/node_modules/slonik-sql-tag-raw/src/sqlTags/raw.ts:18:52)
    at Object.query (server/src/db.ts:28:54)
    at PGStore._asyncQuery (server/node_modules/connect-pg-simple/index.js:308:37)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Related to https://github.com/gajus/slonik/issues/47, I create a pgPool for connect-pg-simple:

// server/src/db.ts
import { Pool } from "pg";
import { createPool } from "slonik";
import { raw } from "slonik-sql-tag-raw";

export const pool = createPool("database-url");

export const pgPool = {
  query: (sql: string, values: any) => pool.query(raw(sql, values)), // line 28
} as Pool;

I'm unclear on which token needs the type property and how to provide it. Any insights you could provide would be much appreciated. 🙏

rochaalexandre commented 2 years ago

@colinrobertbrooks I had the same problem here and it was because I was sending a date with type MomentJs and the slonik was not able to handle it, once I update the value to be a string with a date format it start to work.

colinrobertbrooks commented 2 weeks ago

Not facing this in the more recent versions.