SQL_PARSE_ERROR: SQL string could not be parsed: near LP, "None"
Full error:
I'm getting this error with this query. Is the query correct? Trying to get a list of characters that are not in the DB yet from a list of IDs
schema
Error: SQL_PARSE_ERROR: SQL string could not be parsed: near LP, "None": syntax error at (1, 50)
Error: SQL_PARSE_ERROR: SQL string could not be parsed: near LP, "None": syntax error at (1, 50)
db
.select({ id: characters.id })
.from(characters)
.where(
notExists(
db
.select({ id: characters.id })
.from(characters)
.where(
inArray(
characters.id,
roster.body.members.map((member) => member.character.id),
),
),
),
)
.all();
db
.select({ id: characters.id })
.from(characters)
.where(
notExists(
db
.select({ id: characters.id })
.from(characters)
.where(
inArray(
characters.id,
roster.body.members.map((member) => member.character.id),
),
),
),
)
.all();
const characters = sqliteTable(
'characters',
{
id: integer('id').notNull(),
name: text('name').notNull(),
realm: integer('realm').notNull(),
region: text('region').notNull(),
class: integer('class').notNull(),
faction: integer('faction').notNull(),
},
(c) => ({
unq: unique().on(c.name, c.realm, c.region),
pk: primaryKey(c.name, c.realm, c.region),
idIdx: index('id_index').on(c.id),
nameIdx: index('name_index').on(c.name),
charIdx: uniqueIndex('char_index').on(c.name, c.realm, c.region),
}),
);
const characters = sqliteTable(
'characters',
{
id: integer('id').notNull(),
name: text('name').notNull(),
realm: integer('realm').notNull(),
region: text('region').notNull(),
class: integer('class').notNull(),
faction: integer('faction').notNull(),
},
(c) => ({
unq: unique().on(c.name, c.realm, c.region),
pk: primaryKey(c.name, c.realm, c.region),
idIdx: index('id_index').on(c.id),
nameIdx: index('name_index').on(c.name),
charIdx: uniqueIndex('char_index').on(c.name, c.realm, c.region),
}),
);
4 Replies
what version of drizzle-orm do you have?
Latest (28.3)
Can you please print a query generated by it?
you can add
.getSQL()
after .all()
and console.log itHmm it gives me this when I console log
code
I had to remove
SQL {
decoder: { mapFromDriverValue: [Function: mapFromDriverValue] },
shouldInlineParams: false,
queryChunks: [
StringChunk { value: [Array] },
undefined,
StringChunk { value: [Array] },
undefined,
StringChunk { value: [Array] },
SQL {
decoder: [Object],
shouldInlineParams: false,
queryChunks: [Array]
},
StringChunk { value: [Array] },
SQLiteTable {
id: [SQLiteInteger],
name: [SQLiteText],
normalized_name: [SQLiteText],
realm: [SQLiteInteger],
region: [SQLiteText],
class: [SQLiteInteger],
faction: [SQLiteInteger],
visited: [SQLiteInteger],
[Symbol(drizzle:IsAlias)]: false,
[Symbol(drizzle:ExtraConfigBuilder)]: [Function (anonymous)],
[Symbol(drizzle:IsDrizzleTable)]: true,
[Symbol(drizzle:OriginalName)]: 'characters',
[Symbol(drizzle:Name)]: 'characters',
[Symbol(drizzle:Schema)]: undefined,
[Symbol(drizzle:BaseName)]: 'characters',
[Symbol(drizzle:SQLiteInlineForeignKeys)]: [],
[Symbol(drizzle:Columns)]: [Object]
},
StringChunk { value: [Array] },
SQL {
decoder: [Object],
shouldInlineParams: false,
queryChunks: []
},
StringChunk { value: [Array] },
SQL {
decoder: [Object],
shouldInlineParams: false,
queryChunks: [Array]
},
StringChunk { value: [Array] },
undefined,
StringChunk { value: [Array] },
undefined,
StringChunk { value: [Array] },
undefined,
StringChunk { value: [Array] },
undefined,
StringChunk { value: [Array] },
undefined,
StringChunk { value: [Array] }
]
}
SQL {
decoder: { mapFromDriverValue: [Function: mapFromDriverValue] },
shouldInlineParams: false,
queryChunks: [
StringChunk { value: [Array] },
undefined,
StringChunk { value: [Array] },
undefined,
StringChunk { value: [Array] },
SQL {
decoder: [Object],
shouldInlineParams: false,
queryChunks: [Array]
},
StringChunk { value: [Array] },
SQLiteTable {
id: [SQLiteInteger],
name: [SQLiteText],
normalized_name: [SQLiteText],
realm: [SQLiteInteger],
region: [SQLiteText],
class: [SQLiteInteger],
faction: [SQLiteInteger],
visited: [SQLiteInteger],
[Symbol(drizzle:IsAlias)]: false,
[Symbol(drizzle:ExtraConfigBuilder)]: [Function (anonymous)],
[Symbol(drizzle:IsDrizzleTable)]: true,
[Symbol(drizzle:OriginalName)]: 'characters',
[Symbol(drizzle:Name)]: 'characters',
[Symbol(drizzle:Schema)]: undefined,
[Symbol(drizzle:BaseName)]: 'characters',
[Symbol(drizzle:SQLiteInlineForeignKeys)]: [],
[Symbol(drizzle:Columns)]: [Object]
},
StringChunk { value: [Array] },
SQL {
decoder: [Object],
shouldInlineParams: false,
queryChunks: []
},
StringChunk { value: [Array] },
SQL {
decoder: [Object],
shouldInlineParams: false,
queryChunks: [Array]
},
StringChunk { value: [Array] },
undefined,
StringChunk { value: [Array] },
undefined,
StringChunk { value: [Array] },
undefined,
StringChunk { value: [Array] },
undefined,
StringChunk { value: [Array] },
undefined,
StringChunk { value: [Array] }
]
}
const notExistingCharsInDb = await db
.select({ id: characters.id })
.from(characters)
.where(
notExists(
db
.select({ id: characters.id })
.from(characters)
.where(inArray(characters.id, memberIds)),
),
)
.getSQL();
console.log(notExistingCharsInDb);
const notExistingCharsInDb = await db
.select({ id: characters.id })
.from(characters)
.where(
notExists(
db
.select({ id: characters.id })
.from(characters)
.where(inArray(characters.id, memberIds)),
),
)
.getSQL();
console.log(notExistingCharsInDb);
.all()
because getSQL
doesn't exist on that