Jokerz
Jokerz
Explore posts from servers
DTDrizzle Team
Created by Jokerz on 2/15/2024 in #help
can we filter by a prop on a relation during a query?
eg. watch has watch brands + watch families as relations if i wanted to search across watch name, watch brand name + watch family name should that be possible? current query just using watch name
const items = await ctx.db.query.watch.findMany({
...withCursorPagination({
limit: 10,
cursors: [[schema.watchBrand.name, "desc", cursor]],
}),
where: and(
like(schema.watch.name, `%${input.name}%`),
notInArray(schema.watch.id, usersWatches),
),
with: {
watchBrand: true,
watchFamily: true,
},
});
const items = await ctx.db.query.watch.findMany({
...withCursorPagination({
limit: 10,
cursors: [[schema.watchBrand.name, "desc", cursor]],
}),
where: and(
like(schema.watch.name, `%${input.name}%`),
notInArray(schema.watch.id, usersWatches),
),
with: {
watchBrand: true,
watchFamily: true,
},
});
13 replies
DTDrizzle Team
Created by Jokerz on 10/2/2023 in #help
are timezones saved as utc? for pg
im having an issue where the db is saving -2 instead of -1
2 replies
DTDrizzle Team
Created by Jokerz on 7/8/2023 in #help
foreign key constraint cannot be implemented
/Users/daniel/Documents/Repos/Thatch/thatch-web/node_modules/.pnpm/[email protected]/node_modules/postgres/cjs/src/connection.js:771
const error = Errors.postgres(parseError(x))
^
PostgresError: foreign key constraint "users_to_posts_user_id_users_id_fk" cannot be implemented
/Users/daniel/Documents/Repos/Thatch/thatch-web/node_modules/.pnpm/[email protected]/node_modules/postgres/cjs/src/connection.js:771
const error = Errors.postgres(parseError(x))
^
PostgresError: foreign key constraint "users_to_posts_user_id_users_id_fk" cannot be implemented
import { relations } from "drizzle-orm";
import { pgTable, primaryKey, varchar } from "drizzle-orm/pg-core";

import { posts } from "./posts";
import { users } from "./users";

export const usersToPosts = pgTable(
"users_to_posts",
{
userId: varchar("user_id")
.notNull()
.references(() => users.id),
postId: varchar("post_id")
.notNull()
.references(() => posts.id),
},
(t) => ({
pk: primaryKey(t.userId, t.postId),
})
);

export const usersToPostsRelations = relations(usersToPosts, ({ one }) => ({
post: one(posts, {
fields: [usersToPosts.postId],
references: [posts.id],
}),
user: one(users, {
fields: [usersToPosts.userId],
references: [users.id],
}),
}));
import { relations } from "drizzle-orm";
import { pgTable, primaryKey, varchar } from "drizzle-orm/pg-core";

import { posts } from "./posts";
import { users } from "./users";

export const usersToPosts = pgTable(
"users_to_posts",
{
userId: varchar("user_id")
.notNull()
.references(() => users.id),
postId: varchar("post_id")
.notNull()
.references(() => posts.id),
},
(t) => ({
pk: primaryKey(t.userId, t.postId),
})
);

export const usersToPostsRelations = relations(usersToPosts, ({ one }) => ({
post: one(posts, {
fields: [usersToPosts.postId],
references: [posts.id],
}),
user: one(users, {
fields: [usersToPosts.userId],
references: [users.id],
}),
}));
2 replies
DTDrizzle Team
Created by Jokerz on 6/6/2023 in #help
When trying to push:mysql its warning that schema has changed and data will be lost when it hasnt.
· You're about to change projected_points column type from alter_table_alter_column_set_type to decimal with 689 items
THIS ACTION WILL CAUSE DATA LOSS AND CANNOT BE REVERTED
· You're about to change projected_points column type from alter_table_alter_column_set_type to decimal with 689 items
THIS ACTION WILL CAUSE DATA LOSS AND CANNOT BE REVERTED
No changes have been made ...
11 replies