Reputation: 3
I want to create an index on a table in my Drizzle schema with one caveat, I want the index to be using the HASH index type. In the bottom you will find my current attempt.
However, when I am looking into the Drizzle documentation I see that there may or may not be support for this already, if the documentation is accurate, I would of course prefer to use its methods instead of writing custom SQL. Link to Drizzle documentation
Drizzle index documentation screenshot
The documentation states that only the name
and on()
params are currently supported. However, the example immediately below the statement says otherwise. Additionally, the typescript types mentioned in the example are defined in the codebase. And lastly, why does the using
method take a SQL statement as the input and not a string (e.g. "b-tree", "hash" etc.)? Anyone from the Drizzle ORM community who could give me some guidance on this? Thanks.
export const template = pgTable(
"post",
{
id: text("id")
.primaryKey()
.$defaultFn(() => crypto.randomUUID()),
authorId: text("authorId")
.notNull()
.references(() => users.id, {onDelete: "cascade"}),
},
(table) => {
return {
authorIdIdx: sql`CREATE INDEX "authorIdIdx" ON "post" USING HASH ("authorIdId");`,
};
}
);
Upvotes: 0
Views: 848