Martnart
Martnart
Explore posts from servers
DTDrizzle Team
Created by Martnart on 8/30/2023 in #help
where(gt) with timestamp returns wrong result
Might be a SQL inherent thing, but I'm a bit puzzled as to why this happens: Edit: for terseness I left out some code. I think the issue is clear
const firstThing = await db.insert(table).values({ timestamp: new Date() })
const secondThing = await db.insert(table).values({ timestamp: new Date() })

const result = await db.query.table.findFirst({ where: gt(table.timestamp, firstThing.timestamp) })
console.log(result) // logs firstThing, not secondThing
const firstThing = await db.insert(table).values({ timestamp: new Date() })
const secondThing = await db.insert(table).values({ timestamp: new Date() })

const result = await db.query.table.findFirst({ where: gt(table.timestamp, firstThing.timestamp) })
console.log(result) // logs firstThing, not secondThing
27 replies
DTDrizzle Team
Created by Martnart on 4/28/2023 in #help
TS Errors in Custom Type citext example
4 replies
DTDrizzle Team
Created by Martnart on 4/27/2023 in #help
Check for empty string in postgres
Hi. First post. 🙂 Started looking into migrating our project to drizzle today and am loving it so far. I want to add a not-empty check and from what I gathered from the docs and this example https://github.com/drizzle-team/drizzle-orm/blob/b003e523c637c81e2c522003db03d3d9bd98b723/drizzle-orm/type-tests/pg/tables.ts#L76 (which is the only one I could find) this code should work:
import { boolean, check, pgTable, uniqueIndex, varchar } from 'drizzle-orm/pg-core'
import { uuidPk } from './helpers'
import { sql } from 'drizzle-orm'

export const users = pgTable(
'auth_user',
{
id: uuidPk,
name: varchar('name').notNull(),
password: varchar('password').notNull(),
isAdmin: boolean('is_admin').notNull().default(false),
},
(users) => ({
nameIdx: uniqueIndex('auth_user_name_idx').on(users.name),
notEmptyName: check('notEmptyName', sql`${users.name} <> ''`),
})
)
import { boolean, check, pgTable, uniqueIndex, varchar } from 'drizzle-orm/pg-core'
import { uuidPk } from './helpers'
import { sql } from 'drizzle-orm'

export const users = pgTable(
'auth_user',
{
id: uuidPk,
name: varchar('name').notNull(),
password: varchar('password').notNull(),
isAdmin: boolean('is_admin').notNull().default(false),
},
(users) => ({
nameIdx: uniqueIndex('auth_user_name_idx').on(users.name),
notEmptyName: check('notEmptyName', sql`${users.name} <> ''`),
})
)
But it doesn't :/ the index works, but the check does not. There is no SQL generated for the migration but to be sure I also tested it in runtime after migrating but no luck. Any advice?
7 replies