zerokelvin
zerokelvin
Explore posts from servers
DTDrizzle Team
Created by zerokelvin on 9/18/2024 in #help
How do I order by average rating?
This gets a value without error, but doesn't seem to be returning everything. It's returning facilities that have no reviews, but not the facilities with the highest average reviews
3 replies
DTDrizzle Team
Created by zerokelvin on 4/29/2024 in #help
Drizzle incorrectly building query with DEFAULT instead of $11 in insertion
This is a nasty bug in Drizzle, though
5 replies
DTDrizzle Team
Created by zerokelvin on 4/29/2024 in #help
Drizzle incorrectly building query with DEFAULT instead of $11 in insertion
It seems renaming the columns to not end in _count fixes it
5 replies
DTDrizzle Team
Created by zerokelvin on 4/29/2024 in #help
Drizzle incorrectly building query with DEFAULT instead of $11 in insertion
Huh, I guess the commonality between the two that aren't getting values is that they both end in _count
5 replies
DTDrizzle Team
Created by zerokelvin on 4/29/2024 in #help
Drizzle incorrectly building query with DEFAULT instead of $11 in insertion
Here's my schema, there seems to be no reason why majestic_citation_flow would be treated any differently than the others:
import { pgTable, timestamp, index, text, integer, date } from "drizzle-orm/pg-core";

export const domains = pgTable('domains', {
name: text('name').primaryKey(),
formattedName: text('formatted_name').notNull(),
rootName: text('root_name').notNull(),
tld: text('tld').notNull(),

godaddyAuctionId: integer('godaddy_auction_id').unique(),

auctionPrice: integer('price'),
bidCount: integer('bid_count'),
auctionEndTime: timestamp('auction_end_time', {mode: 'date'}),

majesticTrustFlow: integer('majestic_trust_flow'),
majesticCitationFlow: integer('majestic_citation_flow'),
majesticBacklinkCount: integer('majestic_backlink_count'),
majesticReferringDomainCount: integer('majestic_referring_domain_count'),
});

export const schema = {
domains,
};
import { pgTable, timestamp, index, text, integer, date } from "drizzle-orm/pg-core";

export const domains = pgTable('domains', {
name: text('name').primaryKey(),
formattedName: text('formatted_name').notNull(),
rootName: text('root_name').notNull(),
tld: text('tld').notNull(),

godaddyAuctionId: integer('godaddy_auction_id').unique(),

auctionPrice: integer('price'),
bidCount: integer('bid_count'),
auctionEndTime: timestamp('auction_end_time', {mode: 'date'}),

majesticTrustFlow: integer('majestic_trust_flow'),
majesticCitationFlow: integer('majestic_citation_flow'),
majesticBacklinkCount: integer('majestic_backlink_count'),
majesticReferringDomainCount: integer('majestic_referring_domain_count'),
});

export const schema = {
domains,
};
5 replies
DTDrizzle Team
Created by zerokelvin on 9/18/2023 in #help
Why is my query so much slower when filter by all four latitude/longitude bounds than just three?
My guess is that the problem is with the excessive usage of
coalesce(
json_agg(
json_build_array
coalesce(
json_agg(
json_build_array
11 replies
DTDrizzle Team
Created by zerokelvin on 9/18/2023 in #help
Why is my query so much slower when filter by all four latitude/longitude bounds than just three?
Here's the query it generates:
11 replies
DTDrizzle Team
Created by zerokelvin on 9/18/2023 in #help
Why is my query so much slower when filter by all four latitude/longitude bounds than just three?
@angelelz Is there a way I can get drizzle to print out the SQL query it created to see where the bottleneck might be?
11 replies
DTDrizzle Team
Created by zerokelvin on 7/11/2023 in #help
Internal server error: Error connecting to database: fetch failed
So it seems that either I didn't define my relations correctly, or Drizzle has some performance issue in handling many-to-many relations. Would appreciate any insight anyone has into this!
6 replies
DTDrizzle Team
Created by zerokelvin on 7/11/2023 in #help
Internal server error: Error connecting to database: fetch failed
Commenting out amenityToFacilityRelations in schema.ts dramatically speeds up the code, even compared to circumstances where I wasn't ever referencing that relation
6 replies
DTDrizzle Team
Created by zerokelvin on 7/11/2023 in #help
Internal server error: Error connecting to database: fetch failed
Here's what my amenityToFacility relation looks like:
export const amenityToFacility = pgTable(
"_AmenityToFacility",
{
a: integer("A" as string)
.notNull()
.references(() => amenity.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
b: integer("B" as string)
.notNull()
.references(() => facility.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
},
(table) => {
return {
abUnique: uniqueIndex("_AmenityToFacility_AB_unique" as string).on(
table.a,
table.b
),
bIdx: index().on(table.b),
};
}
);

export const amenityToFacilityRelations = relations(
amenityToFacility,
({ one }) => ({
amenity: one(amenity, {
fields: [amenityToFacility.a],
references: [amenity.id],
}),
facility: one(facility, {
fields: [amenityToFacility.b],
references: [facility.id],
}),
})
);
export const amenityToFacility = pgTable(
"_AmenityToFacility",
{
a: integer("A" as string)
.notNull()
.references(() => amenity.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
b: integer("B" as string)
.notNull()
.references(() => facility.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
},
(table) => {
return {
abUnique: uniqueIndex("_AmenityToFacility_AB_unique" as string).on(
table.a,
table.b
),
bIdx: index().on(table.b),
};
}
);

export const amenityToFacilityRelations = relations(
amenityToFacility,
({ one }) => ({
amenity: one(amenity, {
fields: [amenityToFacility.a],
references: [amenity.id],
}),
facility: one(facility, {
fields: [amenityToFacility.b],
references: [facility.id],
}),
})
);
(please forgive the undescriptive column names, they were autogenerated by prisma)
6 replies
DTDrizzle Team
Created by zerokelvin on 7/11/2023 in #help
Internal server error: Error connecting to database: fetch failed
It looks like when I remove amenityToFacility from the with block, it seems to work as intended (and as quickly as I'd expect)
6 replies
DTDrizzle Team
Created by zerokelvin on 7/11/2023 in #help
Internal server error: Error connecting to database: fetch failed
Here's how I'm connecting to my db:
import { neon, neonConfig } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-http";
import * as schema from './schema';

neonConfig.fetchConnectionCache = true;

export const getDb = (connectionString: string) => {
const sql = neon(connectionString);
const db = drizzle(sql, {schema});

return { db };
};
import { neon, neonConfig } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-http";
import * as schema from './schema';

neonConfig.fetchConnectionCache = true;

export const getDb = (connectionString: string) => {
const sql = neon(connectionString);
const db = drizzle(sql, {schema});

return { db };
};
6 replies