T.T
T.T
Explore posts from servers
DTDrizzle Team
Created by T.T on 11/10/2023 in #help
Table foreign key action fields
Hello, I'd like to use the new foreignKey option inside the table config so that I do not have issues with the identifier being longer than allowed. Is there a way to achieve this whilst also setting the onCascade and onUpdate action properties like you could previously with the .references() syntax? I tried leaving both of them in place (like in the code below) with the hope that it would only generate one foreign key with my name provided and the actions I set with references() but it generates two constraints in the SQL migration file, one with my custom identifier and no actions and one with the default generated constraint name (too long for my DB) and with the actions. I didn't really expected this to work but It would be good to know the best approach going forward to set the custom FK name and also set the actions. Perhaps it is something missed with the latest update for the new foreignKey() functionality? (I could always just change the migration file manually, like I had previously been doing for the foreign key names which were too long but they kept coming back in future migrations with the default generated name, presumably because the _journal.json files have references to the generated fk names which I had overwritten?)
export const testTable = mysqlTable(
'test_table',
{
id: int('id').autoincrement().primaryKey(),
userId: int('user_id')
.notNull()
.references(() => users.id, { onDelete: 'cascade', onUpdate: 'cascade' }),
},
(table) => {
return {
userFk: foreignKey({
name: 'test_table_user_id_fk',
columns: [table.userId],
foreignColumns: [users.id],
}),
};
},
);
export const testTable = mysqlTable(
'test_table',
{
id: int('id').autoincrement().primaryKey(),
userId: int('user_id')
.notNull()
.references(() => users.id, { onDelete: 'cascade', onUpdate: 'cascade' }),
},
(table) => {
return {
userFk: foreignKey({
name: 'test_table_user_id_fk',
columns: [table.userId],
foreignColumns: [users.id],
}),
};
},
);
2 replies
TtRPC
Created by T.T on 11/3/2023 in #❓-help
Accessing QueryFunctionContext within server queries
Hello, I know that the field 'direction' is a new addition within react query v5 as part of the QueryFunctionContext object https://tanstack.com/query/v5/docs/react/guides/query-functions#queryfunctioncontext and that work on compatibility with this version is happening in the 'next' release of TRPC. However, this is a more general question about accessing data within the QueryFunctionContext when utilising TRPC, despite my examples including the new field. If I were not to be using TRPC I would have access to that object as an argument in my query function and I would construct my URL with that data included. Obviously the benefits of TRPC include the automatic generation of my query function to a corresponding server procedure, however this process does not provide me access to the fields of the context on the server. Is there a good way to pass this field to my server procedures so that I could determine how to adapt my database queries for cursor based pagination? The motivating example would be: I have a cursor which is either the first Id of my nodes or the last Id of my nodes (relay pagination specification). I would then like to know if I should paginate backwards with the ID or forward. This field on the QueryFunctionContect would allow me to determine that. There are a few 'hacky' solutions I could think of such as storing the direction manually in a ref when pressing a button which then calls the fetchNextPage or fetchPreviousPage functions and with this pass the value in the ref as an input to my infiniteQuery but I'd like to avoid these if there are any good approaches already provided in the library. Thanks for your time and hard work on the library!
2 replies