Module '"drizzle-orm/mysql-core"' has no exported member 'unique'.ts(2305)

Getting this error when trying to import unique
import {
text,
unique, // erroring out
mysqlTable,
serial,
mysqlEnum,
} from 'drizzle-orm/mysql-core';
import {
text,
unique, // erroring out
mysqlTable,
serial,
mysqlEnum,
} from 'drizzle-orm/mysql-core';
10 Replies
DiamondDragon
DiamondDragon2y ago
me too with pg
ShiftyMcCool
ShiftyMcCool2y ago
I'm here for the same reason in pg. Are the docs out of date? It seems that uniqueIndex exists but the docs don't use it. This syntax from the docs doesn't work, even with uniqueIndex
export const user = pgTable('user', {
id: integer('id').unique(),
});
export const user = pgTable('user', {
id: integer('id').unique(),
});
But, this does:
export const composite = pgTable('composite_example', {
id: integer('id'),
}, (t) => ({
unq: uniqueIndex().on(t.id),
}));
export const composite = pgTable('composite_example', {
id: integer('id'),
}, (t) => ({
unq: uniqueIndex().on(t.id),
}));
Hope this helps, but the docs should really be updated if this is the correct way to do it now
DiamondDragon
DiamondDragon2y ago
@shiftymccool @boxer01 not sure if you all found a solution but seems like i can add it now, but ts is telling me its not being read for some reason
DiamondDragon
DiamondDragon2y ago
@Andrew Sherman am i reading this right, is there not a unique function in the latest version? https://www.npmjs.com/package/drizzle-orm/v/0.27.2?activeTab=code
npm
drizzle-orm
Drizzle ORM package for SQL databases. Latest version: 0.27.2, last published: 7 days ago. Start using drizzle-orm in your project by running npm i drizzle-orm. There are 20 other projects in the npm registry using drizzle-orm.
Andrii Sherman
there is a unique function in latest if you want to use unique on column level - no need to imoprt anything. It's already available on column level if you want to have composite unique on 2+ columns, than you need to import this function and use in 3 param of pgTable
Andrii Sherman
you can find a full set of examples here
DiamondDragon
DiamondDragon2y ago
ah ok thx. saw the unique import in the docs so was wondering if it was required
Boxer
BoxerOP2y ago
it's showing up now, but it doesn't seem to be enforced:
export const channelSchema = mysqlTable(
'channels',
{
id: serial('id').primaryKey(),
channel_id: int('channel_id').notNull().unique(),
// etc
export const channelSchema = mysqlTable(
'channels',
{
id: serial('id').primaryKey(),
channel_id: int('channel_id').notNull().unique(),
// etc
I am able to still insert records into the db with the same number in the channel_id column
Want results from more Discord servers?
Add your server