Open lancejpollard opened 2 weeks ago
await createGinIndex(
db,
'searches_text_language_gin_index',
'searches',
['language_id', 'text gin_trgm_ops'],
'WHERE is_phonetic = FALSE',
)
async function createGinIndex(
db: Kysely<any>,
indexName: string,
tableName: string,
columns: Array<string>,
extra: string
) {
const columnsStr = columns.join(", ");
const query = sql`CREATE INDEX ${indexName} ON ${tableName} USING gin (${columnsStr}) ${extra}`;
console.log(query);
await query.execute(db);
// let builder = db.schema
// .createIndex(indexName)
// .on(tableName)
// .using('gin')
// .expression(sql`USING gin (${columnsStr})`)
// if (cb) {
// builder = cb(builder)
// }
// return await builder.execute()
}
Error:
RawBuilderImpl {}
failed to execute migration "foo_0001"
failed to migrate
error: syntax error at or near "$1"
How can you write this sort of query with Kysely?
I know you can do this so far:
But how about specifying the
gin_trgm_ops
and the rest of the columns, is there a nice way? Perhaps:ClaudeAI is suggesting these two:
Any of these work or ideal? What is recommended?
And same for this:
Is that just this? (Is there a better way)?
Also (tangent), do I need to do this somewhere (and how to do it in Kysely)?
Thanks for the help.