pdina
pdina
DTDrizzle Team
Created by pdina on 5/18/2023 in #help
Help with raw query
The following query is all raw. Is there a way to make SQL raw only the part of the where clause? (or still better a way to not use raw sql at all)
await dbConn.execute<User>(
sql`select * from ${UserModel} where similarity("name", ${q}) > ${treshold}`
);
await dbConn.execute<User>(
sql`select * from ${UserModel} where similarity("name", ${q}) > ${treshold}`
);
2 replies
DTDrizzle Team
Created by pdina on 5/18/2023 in #help
Create GIN index in Postgres
I need to create this index in postgres:
CREATE INDEX users_name_gin_trgm_idx ON users USING gin (name gin_trgm_ops);
CREATE INDEX users_name_gin_trgm_idx ON users USING gin (name gin_trgm_ops);
and this is the code I have:
export const UserModel = pgTable(
'users',
{
id: serial('id').primaryKey(),
name: varchar('name'),
email: varchar('email', { length: 255 })
},
(table) => {
return {
name: index('name').on(table.name)
// SPACE FOR INDEX DECLARATION!
};
}
);
export const UserModel = pgTable(
'users',
{
id: serial('id').primaryKey(),
name: varchar('name'),
email: varchar('email', { length: 255 })
},
(table) => {
return {
name: index('name').on(table.name)
// SPACE FOR INDEX DECLARATION!
};
}
);
Reading the docs on GitHub I was able to create "normal" index, but it's not clear how to specify index configuration options (like the type of index etc).
10 replies