Tobias
Tobias
Explore posts from servers
CDCloudflare Developers
Created by Tobias on 8/9/2024 in #workers-help
SSE - Server Sent Events
Is it possible to use server sent events in Cloudflare worker? If so, how does it work with the limit of 30 seconds per request? As my plan is to have a client listen to server sent events as long as they want.
1 replies
CDCloudflare Developers
Created by Tobias on 7/24/2024 in #pages-help
Trying to delete a cloudflare pages project
But getting the following error message: An unknown error occured. Contact your account team or Cloudflare support: https://cfl.re/3WgEyrH. (Code: 8000000) But I am not allowed to contact CF support as I have a free account, any suggestions?
8 replies
DTDrizzle Team
Created by Tobias on 6/25/2024 in #help
Insert returning and left join
Is it possible to do a leftJoin when returning() on an insert? Pseudo code that do not work (but to show an example of what I want). I.e. I want the user object returned on each splits I insert.
const [splits] = await db.insert(transactionSplitsTable).values(insert_splits).returning().leftJoin(usersTable, eq(usersTable.id, transactionSplitsTable.user_id)
const [splits] = await db.insert(transactionSplitsTable).values(insert_splits).returning().leftJoin(usersTable, eq(usersTable.id, transactionSplitsTable.user_id)
3 replies
DTDrizzle Team
Created by Tobias on 5/23/2024 in #help
Two tables that references each other
No description
3 replies
DTDrizzle Team
Created by Tobias on 4/12/2024 in #help
nullsNotDistinct on composite unique
I have the following table
export const customersTable = pgTable("customers", {
id: serial('id').primaryKey(),
first_name: text('first_name'),
last_name: text('last_name'),
email: text('email'),
tenant_id: integer('tenant_id').references(() => tenantsTable.id, { onDelete: 'cascade' }).notNull()
}, (t) => ({
unq: unique().on(t.email, t.tenant_id).nullsNotDistinct()
}));
export const customersTable = pgTable("customers", {
id: serial('id').primaryKey(),
first_name: text('first_name'),
last_name: text('last_name'),
email: text('email'),
tenant_id: integer('tenant_id').references(() => tenantsTable.id, { onDelete: 'cascade' }).notNull()
}, (t) => ({
unq: unique().on(t.email, t.tenant_id).nullsNotDistinct()
}));
My wish is to be able to add how many customers as possible to a specific tenant_id with null email and no constraint. But only one customer per email and per tenant should be allowed. The above solution doesn't work and I want to be able to specifically target "nullsNotDisticint" on the email column only and not the whole composite unique key. How can I solve this?
1 replies
DTDrizzle Team
Created by Tobias on 3/6/2024 in #help
drizzle-kit push:pg and sql commands
I have a schema that I can easily push to my PostgreSQL database. But whenever I have something I want to do outside what I can define within the schema, I need to do a manual sql command in my database. For example I want to run
alter table "table_name" enable row level security;
alter table "table_name" enable row level security;
for my tables, and I want to add that so it is applied when I run drizzle-kit push:pg. Is this possible?
2 replies
DTDrizzle Team
Created by Tobias on 2/16/2024 in #help
Filter on many to many relationship
I want to find all sites where a user is a member in. I have 3 tables that I have setup relations between
export const users = pgTable("users", {
id: text("id").primaryKey(),
name: text("name"),
email: text("email").unique(),
avatarUrl: text('avatar_url')
});

export const sites = pgTable("sites", {
id: serial("id").primaryKey(),
createdAt: timestamp('created_at', {
withTimezone: true
}).defaultNow(),
uuid: uuid('uuid').defaultRandom(),
name: text("name").notNull(),
slug: text("slug").unique().notNull()
});

export const usersRelations = relations(users, ({ many }) => ({
sites: many(siteMembers),
}));

export const sitesRelations = relations(sites, ({ many }) => ({
members: many(siteMembers),
}));

export const siteMembers = pgTable('site_members', {
siteId: integer('site_id').references(() => sites.id, { onDelete: 'cascade' }),
userId: text("user_id").notNull().references(() => users.id, { onDelete: 'cascade' })
}, (table) => {
return {
pk: primaryKey(table.siteId, table.userId),
}

});

export const userSiteMembersRelations = relations(siteMembers, ({ one }) => ({
sites: one(sites, {
fields: [siteMembers.siteId],
references: [sites.id],
}),
user: one(users, {
fields: [siteMembers.userId],
references: [users.id],
}),
}));
export const users = pgTable("users", {
id: text("id").primaryKey(),
name: text("name"),
email: text("email").unique(),
avatarUrl: text('avatar_url')
});

export const sites = pgTable("sites", {
id: serial("id").primaryKey(),
createdAt: timestamp('created_at', {
withTimezone: true
}).defaultNow(),
uuid: uuid('uuid').defaultRandom(),
name: text("name").notNull(),
slug: text("slug").unique().notNull()
});

export const usersRelations = relations(users, ({ many }) => ({
sites: many(siteMembers),
}));

export const sitesRelations = relations(sites, ({ many }) => ({
members: many(siteMembers),
}));

export const siteMembers = pgTable('site_members', {
siteId: integer('site_id').references(() => sites.id, { onDelete: 'cascade' }),
userId: text("user_id").notNull().references(() => users.id, { onDelete: 'cascade' })
}, (table) => {
return {
pk: primaryKey(table.siteId, table.userId),
}

});

export const userSiteMembersRelations = relations(siteMembers, ({ one }) => ({
sites: one(sites, {
fields: [siteMembers.siteId],
references: [sites.id],
}),
user: one(users, {
fields: [siteMembers.userId],
references: [users.id],
}),
}));
Now I am trying to figure out how to query all sites where user with a specific ID is a member in. But when I do the following query, I just get all sites but with an empty array for the sites where the user is not a member in. My goal is to only get the sites where the user is a member in. How can I query this?
await db.query.sites.findMany({
with: {
members: {
where: (members, { eq }) => eq(members.userId, user.id)
},
}
})
await db.query.sites.findMany({
with: {
members: {
where: (members, { eq }) => eq(members.userId, user.id)
},
}
})
4 replies
CDCloudflare Developers
Created by Tobias on 9/7/2023 in #general-help
Cloudflare for SaaS custom domains webhooks for status updates
No description
5 replies
CDCloudflare Developers
Created by Tobias on 7/17/2023 in #pages-help
Adding custom domain with to cloudflare pages with åäö in it (IDN)
8 replies