Dari
Dari
Explore posts from servers
DTDrizzle Team
Created by Dari on 10/11/2024 in #help
Resolved: Need help with my multi column primary and foreign key table
shall i open an issue?
12 replies
DTDrizzle Team
Created by Dari on 10/11/2024 in #help
Resolved: Need help with my multi column primary and foreign key table
@Andrew Sherman is this intended behaviour or a bug?
12 replies
DTDrizzle Team
Created by Dari on 10/11/2024 in #help
Resolved: Need help with my multi column primary and foreign key table
Found the issue.
pk: primaryKey({ columns: [table.userId, table.type, table.identifier] }),
pk: primaryKey({ columns: [table.userId, table.type, table.identifier] }),
The columns need to be in the correct order. So it worked as soon as I changed it to:
pk: primaryKey({ columns: [table.userId, table.identifier, table.type] }),
pk: primaryKey({ columns: [table.userId, table.identifier, table.type] }),
12 replies
DTDrizzle Team
Created by Dari on 10/11/2024 in #help
Resolved: Need help with my multi column primary and foreign key table
The first db push works fine. On a second call without any changes it still tries to "alter" the table. First db:push:
CREATE TABLE `userAsyncTask` (
`userId` text NOT NULL,
`identifier` text NOT NULL,
`type` text NOT NULL,
`data` text,
`startedAt` integer NOT NULL,
`timeoutAt` integer,
PRIMARY KEY(`userId`, `type`, `identifier`),
FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE cascade ON DELETE cascade
);
CREATE TABLE `userAsyncTask` (
`userId` text NOT NULL,
`identifier` text NOT NULL,
`type` text NOT NULL,
`data` text,
`startedAt` integer NOT NULL,
`timeoutAt` integer,
PRIMARY KEY(`userId`, `type`, `identifier`),
FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE cascade ON DELETE cascade
);
Second db:push:
CREATE TABLE `__new_userAsyncTask` (
`userId` text NOT NULL,
`identifier` text NOT NULL,
`type` text NOT NULL,
`data` text,
`startedAt` integer NOT NULL,
`timeoutAt` integer,
PRIMARY KEY(`userId`, `type`, `identifier`),
FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE cascade ON DELETE cascade
);

INSERT INTO `__new_userAsyncTask`("userId", "identifier", "type", "data", "startedAt", "timeoutAt") SELECT "userId", "identifier", "type", "data", "startedAt", "timeoutAt" FROM `userAsyncTask`;
DROP TABLE `userAsyncTask`;
ALTER TABLE `__new_userAsyncTask` RENAME TO `userAsyncTask`;
CREATE TABLE `__new_userAsyncTask` (
`userId` text NOT NULL,
`identifier` text NOT NULL,
`type` text NOT NULL,
`data` text,
`startedAt` integer NOT NULL,
`timeoutAt` integer,
PRIMARY KEY(`userId`, `type`, `identifier`),
FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE cascade ON DELETE cascade
);

INSERT INTO `__new_userAsyncTask`("userId", "identifier", "type", "data", "startedAt", "timeoutAt") SELECT "userId", "identifier", "type", "data", "startedAt", "timeoutAt" FROM `userAsyncTask`;
DROP TABLE `userAsyncTask`;
ALTER TABLE `__new_userAsyncTask` RENAME TO `userAsyncTask`;
Any suggestions? I've tried defining the foreign key with the foreignKey function and directly in the schema field with .references(). Same result
12 replies
DTDrizzle Team
Created by brettlyc on 9/19/2024 in #help
transaction is not defined
btw drizzle rollsback automatically if any error is thrown within the transaction function. So you wouldn need to try catch and if an error occurs it should rollback as expected
11 replies
DTDrizzle Team
Created by brettlyc on 9/19/2024 in #help
transaction is not defined
const createNewSchedules = async (scheduleData, store) => {
const startTime = getDate(scheduleData.start_time)
const endTime = getDate(scheduleData.end_time)
const daysToSchedule = getDaysBetween(scheduleData.dates)

return await db.transaction(async (tx) => {
await Promise.all(daysToSchedule.map(async (date) => {
scheduleData.date = new Date(date)
scheduleData.start_time = getDate(date).set('hour', startTime.get('hour')).set('minute', startTime.get('minute')).toDate()
scheduleData.end_time = getDate(date).set('hour', endTime.get('hour')).set('minute', endTime.get('minute')).toDate()

const validatedSchedule = await TechnicianSchedule.parseAsync(scheduleData)
if (validatedSchedule.errors) throw validatedSchedule.errors

try {
await verifyTechSchedules(validatedSchedule)

await tx.insert(technicianSchedules).values({
...validatedSchedule,
store,
schedule_created: new Date()
})
} catch (err) {
tx.rollback()
}
}))
})
}
const createNewSchedules = async (scheduleData, store) => {
const startTime = getDate(scheduleData.start_time)
const endTime = getDate(scheduleData.end_time)
const daysToSchedule = getDaysBetween(scheduleData.dates)

return await db.transaction(async (tx) => {
await Promise.all(daysToSchedule.map(async (date) => {
scheduleData.date = new Date(date)
scheduleData.start_time = getDate(date).set('hour', startTime.get('hour')).set('minute', startTime.get('minute')).toDate()
scheduleData.end_time = getDate(date).set('hour', endTime.get('hour')).set('minute', endTime.get('minute')).toDate()

const validatedSchedule = await TechnicianSchedule.parseAsync(scheduleData)
if (validatedSchedule.errors) throw validatedSchedule.errors

try {
await verifyTechSchedules(validatedSchedule)

await tx.insert(technicianSchedules).values({
...validatedSchedule,
store,
schedule_created: new Date()
})
} catch (err) {
tx.rollback()
}
}))
})
}
Try this, I think it should fix it.
11 replies
DTDrizzle Team
Created by brettlyc on 9/19/2024 in #help
transaction is not defined
transaction does not return the transaction. Instead it provides the transaction within the lambda function. So it definetly needs a function which executes within the transaction. Something like this:
await db.transaction((trx) => {
// use and pass trx where needed
trx.insert(helloTable).values({ name: "hello" });
await myRandomFunction(trx, randomParameters);
});
await db.transaction((trx) => {
// use and pass trx where needed
trx.insert(helloTable).values({ name: "hello" });
await myRandomFunction(trx, randomParameters);
});
Basically you need to wrap the code with
db.transaction((trx) => {
//...yourCode
});
db.transaction((trx) => {
//...yourCode
});
Hope that helps 🙂
11 replies
DTDrizzle Team
Created by Dari on 7/3/2024 in #help
Drizzle Push to Turso fails on third attempt
Wow that solved it. Thank you very much!
3 replies
TTCTheo's Typesafe Cult
Created by traches on 10/20/2023 in #questions
Drizzle & Planetscale data migration workflow
the --custom flag worked for me. But how do you call drizzle's provided migrator function appropriately? Because im getting an ERR_UNKNOWN_FILE_EXTENSION error
7 replies
TTCTheo's Typesafe Cult
Created by Dari on 3/22/2023 in #questions
How to chain useQuery calls? | Use result from one query as input for another?
Thank you very much
23 replies
TTCTheo's Typesafe Cult
Created by Dari on 3/22/2023 in #questions
How to chain useQuery calls? | Use result from one query as input for another?
and it's just typescript complaining
23 replies
TTCTheo's Typesafe Cult
Created by Dari on 3/22/2023 in #questions
How to chain useQuery calls? | Use result from one query as input for another?
you are absolutely right with ? it worked
23 replies
TTCTheo's Typesafe Cult
Created by Dari on 3/22/2023 in #questions
How to chain useQuery calls? | Use result from one query as input for another?
never mind sorry
23 replies
TTCTheo's Typesafe Cult
Created by Dari on 3/22/2023 in #questions
How to chain useQuery calls? | Use result from one query as input for another?
but it leads to a runtime error
23 replies
TTCTheo's Typesafe Cult
Created by Dari on 3/22/2023 in #questions
How to chain useQuery calls? | Use result from one query as input for another?
no i didn't destruct it
23 replies
TTCTheo's Typesafe Cult
Created by Dari on 3/22/2023 in #questions
How to chain useQuery calls? | Use result from one query as input for another?
Not working, because ids cant be undefined / null
23 replies
TTCTheo's Typesafe Cult
Created by Dari on 3/22/2023 in #questions
How to chain useQuery calls? | Use result from one query as input for another?
yup
23 replies
TTCTheo's Typesafe Cult
Created by Dari on 3/22/2023 in #questions
How to chain useQuery calls? | Use result from one query as input for another?
Im still running into an issue, tho:
trpc.example.someQuery.useQuery({
ids: firstQuery.data!.ids // data is undefined ! didn't work
}, {
enabled: !!firstQuery.data?.ids
});
trpc.example.someQuery.useQuery({
ids: firstQuery.data!.ids // data is undefined ! didn't work
}, {
enabled: !!firstQuery.data?.ids
});
23 replies
TTCTheo's Typesafe Cult
Created by Dari on 3/22/2023 in #questions
How to chain useQuery calls? | Use result from one query as input for another?
Of course, but in my specific case i am mapping the first query with data that is only available client and i don't want it to be passed to the server
23 replies
TTCTheo's Typesafe Cult
Created by Dari on 1/9/2023 in #questions
How bad is revealing ids really?
alright, thank you
9 replies