Fyzz
Fyzz
Explore posts from servers
DTDrizzle Team
Created by Fyzz on 3/30/2024 in #help
Turso DB reads (alot)
Thanks guys I’ll take a look
6 replies
DTDrizzle Team
Created by Hussein on 10/27/2023 in #help
example on users table with followers and follows?
then add the uniqe indexes / indexes for your querying needs, probably the follower_user_id and following_user_id and to prevent overlapping follows follower_user_id the id of the user who doing the following (currentUser) following_user_id the id of the user being followed
3 replies
DTDrizzle Team
Created by Hussein on 10/27/2023 in #help
example on users table with followers and follows?
Someone may have a better one but this is how id do it
export const users = mysqlTable("users", {
id: serial("id").autoincrement().primaryKey(),
// other user data
});

export const usersRelations = relations(users, ({ many }) => ({
following: many(follows),
followers: many(follows),
}));


export const follows = mysqlTable("follows", {
id: serial("id").autoincrement().primaryKey(),
follower_user_id: int("follower_user_id").notNull(),
following_user_id: int("following_user_id").notNull(),
followed_at: timestamp("followed_at").defaultNow(),
// other follow data
});

const followsRelations = relations(follows, ({ one }) => ({
follower: one(users, {
fields: [follows.follower_user_id],
references: [users.id],
}),
following: one(users, {
fields: [follows.following_user_id],
references: [users.id],
}),
}));
export const users = mysqlTable("users", {
id: serial("id").autoincrement().primaryKey(),
// other user data
});

export const usersRelations = relations(users, ({ many }) => ({
following: many(follows),
followers: many(follows),
}));


export const follows = mysqlTable("follows", {
id: serial("id").autoincrement().primaryKey(),
follower_user_id: int("follower_user_id").notNull(),
following_user_id: int("following_user_id").notNull(),
followed_at: timestamp("followed_at").defaultNow(),
// other follow data
});

const followsRelations = relations(follows, ({ one }) => ({
follower: one(users, {
fields: [follows.follower_user_id],
references: [users.id],
}),
following: one(users, {
fields: [follows.following_user_id],
references: [users.id],
}),
}));
3 replies
DTDrizzle Team
Created by Fyzz on 8/30/2023 in #help
PostgreSQL "type serial does not exist"
Ahh okay that makes sense because I wiped all tables from my db and then re pushed it, and it worked after that! Thankfully I only had a few tables and had no real data yet
12 replies
DTDrizzle Team
Created by Fyzz on 8/30/2023 in #help
PostgreSQL "type serial does not exist"
ALTER TABLE "users" ALTER COLUMN "id" SET DATA TYPE serial;
12 replies
DTDrizzle Team
Created by Fyzz on 8/11/2023 in #help
"mode" not defined in drizzle config 0.28.1
Oh perfect! Thank you @Andrew Sherman
10 replies
DTDrizzle Team
Created by Fyzz on 8/11/2023 in #help
"mode" not defined in drizzle config 0.28.1
I’ve tried both the error is throwing in ts build too 😅
10 replies
DTDrizzle Team
Created by Fyzz on 7/30/2023 in #help
Query a table based on related table
This is what im looking for I belive 😅 maybe someone could tell me if this is correct
4 replies
DTDrizzle Team
Created by Fyzz on 7/30/2023 in #help
Query a table based on related table
const visitList = await db.query.jobs
.findMany({
where: eq(jobs.company_id, user.privateMetadata.company_id as string),
columns: {},
with: {
visits: {
where: sql`DATE(${
visits.date
}) between ${startOfCalendar.toDate()} and ${endOfCalendar.toDate()}`,
},
},
})
.then((jobs) => jobs.flatMap((job) => job.visits))
const visitList = await db.query.jobs
.findMany({
where: eq(jobs.company_id, user.privateMetadata.company_id as string),
columns: {},
with: {
visits: {
where: sql`DATE(${
visits.date
}) between ${startOfCalendar.toDate()} and ${endOfCalendar.toDate()}`,
},
},
})
.then((jobs) => jobs.flatMap((job) => job.visits))
4 replies
DTDrizzle Team
Created by Fyzz on 7/30/2023 in #help
Query a table based on related table
// Jobs
export const jobs = mysqlTable("jobs", {
id: varchar("id", { length: 50 }).primaryKey(),
title: varchar("title", { length: 100 }).notNull(),
instructions: varchar("instructions", { length: 400 }),
company_id: varchar("company_id", { length: 50 }).notNull(),
type: mysqlEnum("type", ["one_off", "recurring", "as_needed"]),
property_id: varchar("property_id", { length: 50 }).notNull(),
client_id: varchar("client_id", { length: 50 }).notNull(),
rrule: varchar("rrule", { length: 500 }).notNull(),
start_date: datetime("start_date").notNull(),
end_date: datetime("end_date").notNull(),
line_items: json("line_items").$type<LineItem[]>().default([]),
status: mysqlEnum("status", ["active", "complete"])
.default("active")
.notNull(),
})

export const jobsRelations = relations(jobs, ({ one, many }) => ({
property: one(properties, {
fields: [jobs.property_id],
references: [properties.id],
}),
client: one(clients, {
fields: [jobs.client_id],
references: [clients.id],
}),
company: one(companies, {
fields: [jobs.company_id],
references: [companies.id],
}),
visits: many(visits),
employees: many(crews),
}))

// Visits
export const visits = mysqlTable("visits", {
id: serial("id").autoincrement().primaryKey(),
job_id: varchar("job_id", { length: 50 }).notNull(),
time_in: datetime("time_in"),
time_out: datetime("time_out"),
time_total: int("time_total").default(0).notNull(),
date: datetime("date").notNull(),
status: mysqlEnum("status", [
"waiting",
"active",
"skipped",
"complete",
"invoiced",
])
.default("waiting")
.notNull(),
line_items: json("line_items").$type<LineItem[]>().default([]),
visit_notes: varchar("visit_notes", { length: 400 }),
visit_price: decimal("visit_price", { precision: 10, scale: 2 }),
})

export const visitsRelations = relations(visits, ({ one }) => ({
job: one(jobs, {
fields: [visits.job_id],
references: [jobs.id],
})
}))
// Jobs
export const jobs = mysqlTable("jobs", {
id: varchar("id", { length: 50 }).primaryKey(),
title: varchar("title", { length: 100 }).notNull(),
instructions: varchar("instructions", { length: 400 }),
company_id: varchar("company_id", { length: 50 }).notNull(),
type: mysqlEnum("type", ["one_off", "recurring", "as_needed"]),
property_id: varchar("property_id", { length: 50 }).notNull(),
client_id: varchar("client_id", { length: 50 }).notNull(),
rrule: varchar("rrule", { length: 500 }).notNull(),
start_date: datetime("start_date").notNull(),
end_date: datetime("end_date").notNull(),
line_items: json("line_items").$type<LineItem[]>().default([]),
status: mysqlEnum("status", ["active", "complete"])
.default("active")
.notNull(),
})

export const jobsRelations = relations(jobs, ({ one, many }) => ({
property: one(properties, {
fields: [jobs.property_id],
references: [properties.id],
}),
client: one(clients, {
fields: [jobs.client_id],
references: [clients.id],
}),
company: one(companies, {
fields: [jobs.company_id],
references: [companies.id],
}),
visits: many(visits),
employees: many(crews),
}))

// Visits
export const visits = mysqlTable("visits", {
id: serial("id").autoincrement().primaryKey(),
job_id: varchar("job_id", { length: 50 }).notNull(),
time_in: datetime("time_in"),
time_out: datetime("time_out"),
time_total: int("time_total").default(0).notNull(),
date: datetime("date").notNull(),
status: mysqlEnum("status", [
"waiting",
"active",
"skipped",
"complete",
"invoiced",
])
.default("waiting")
.notNull(),
line_items: json("line_items").$type<LineItem[]>().default([]),
visit_notes: varchar("visit_notes", { length: 400 }),
visit_price: decimal("visit_price", { precision: 10, scale: 2 }),
})

export const visitsRelations = relations(visits, ({ one }) => ({
job: one(jobs, {
fields: [visits.job_id],
references: [jobs.id],
})
}))
4 replies
DTDrizzle Team
Created by Startup Spells 🪄 Newsletter Guy on 6/22/2023 in #help
Drizzle Kit Push & Generate gives weird error
This fix seemed to work
//tsconfig.json
{
"compilerOptions": {
...
// Solution is to update es5 to ES2015
"target": "es5",
}
}
//tsconfig.json
{
"compilerOptions": {
...
// Solution is to update es5 to ES2015
"target": "es5",
}
}
"target": "ES2015",
5 replies
DTDrizzle Team
Created by Startup Spells 🪄 Newsletter Guy on 6/22/2023 in #help
Drizzle Kit Push & Generate gives weird error
Any update on this im getting this error as well
5 replies
DTDrizzle Team
Created by makaron pelnoziarnisty on 3/30/2023 in #help
Invalid default value for timestamp
If I figure it out I’ll post in here 😁
15 replies
DTDrizzle Team
Created by makaron pelnoziarnisty on 3/30/2023 in #help
Invalid default value for timestamp
For now I just removed the created at and updated at, lol
15 replies
DTDrizzle Team
Created by makaron pelnoziarnisty on 3/30/2023 in #help
Invalid default value for timestamp
looks to be the same error on their end ill check the docs
create table users (
id varchar(256) not null primary key
created_at timestamp(2) not null default current_timestamp()
);
target: hobby.-.primary: vttablet: rpc error: code = InvalidArgument desc = You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'created_at timestamp(2) not null default now() )' at line 3 (errno 1064) (sqlstate 42000) (CallerID: oyl1qfn8efl5jv0d0jot): Sql: "create table users (\nid varchar(256) not null primary key\ncreated_at timestamp(2) not null default now()\n)", BindVars: {REDACTED}
create table users (
id varchar(256) not null primary key
created_at timestamp(2) not null default current_timestamp()
);
target: hobby.-.primary: vttablet: rpc error: code = InvalidArgument desc = You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'created_at timestamp(2) not null default now() )' at line 3 (errno 1064) (sqlstate 42000) (CallerID: oyl1qfn8efl5jv0d0jot): Sql: "create table users (\nid varchar(256) not null primary key\ncreated_at timestamp(2) not null default now()\n)", BindVars: {REDACTED}
15 replies
DTDrizzle Team
Created by makaron pelnoziarnisty on 3/30/2023 in #help
Invalid default value for timestamp
Ps I am also using planetscale
15 replies
DTDrizzle Team
Created by makaron pelnoziarnisty on 3/30/2023 in #help
Invalid default value for timestamp
Just inquiring further about this, any fix yet? I did as suggested and changed .defaultNow() to
.default(sql`CURRENT_TIMESTAMP`)
.default(sql`CURRENT_TIMESTAMP`)
but i'm still receiving the same error
15 replies