SQL_PARSE_ERROR: SQL string could not be parsed: near LP, "None"

Full error:
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)
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
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();
schema
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
Andrii Sherman
Andrii Sherman16mo ago
what version of drizzle-orm do you have?
Meexa
MeexaOP16mo ago
Latest (28.3)
Andrii Sherman
Andrii Sherman16mo ago
Can you please print a query generated by it? you can add .getSQL() after .all() and console.log it
Meexa
MeexaOP16mo ago
Hmm it gives me this when I console log
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] }
]
}
code
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);
I had to remove .all() because getSQL doesn't exist on that
Want results from more Discord servers?
Add your server