shreddish
shreddish
DTDrizzle Team
Created by tomeverson on 8/18/2023 in #help
ERROR: operator does not exist: uuid = character varying
yeah additionally this is all done through query builder which AFAIK you aren't specifying the joins its doing it for you - most likely meaning my nested relations are causing issues for it
19 replies
DTDrizzle Team
Created by tomeverson on 8/18/2023 in #help
ERROR: operator does not exist: uuid = character varying
i've been playing around and now I'm getting this error (granted i think i've abused the QB model and have some extremely complex queries to build) so maybe i need to rethink how im utilizing it but not sure if theres an easier route i can take in the meantime
detail: 'There is a column named "vehicle_class_id" in table "customers_projects_jobs_outboundLoads_supportVehicles_vehicle_c", but it cannot be referenced from this part of the query.',
hint: 'To reference that column, you must mark this subquery with LATERAL.',
detail: 'There is a column named "vehicle_class_id" in table "customers_projects_jobs_outboundLoads_supportVehicles_vehicle_c", but it cannot be referenced from this part of the query.',
hint: 'To reference that column, you must mark this subquery with LATERAL.',
19 replies
DTDrizzle Team
Created by tomeverson on 8/18/2023 in #help
ERROR: operator does not exist: uuid = character varying
yeah its weird because i have an "identical" relation on the job model for supportEquipment and it doesn't throw the type error
19 replies
DTDrizzle Team
Created by tomeverson on 8/18/2023 in #help
ERROR: operator does not exist: uuid = character varying
export const jobSupportEquipment = pgTable(
'job_support_equipment',
{
id: uuid('id').primaryKey().defaultRandom(),
jobId: uuid('job_id')
.references(() => jobs.id)
.notNull(),
equipmentId: uuid('equipment_id')
.references(() => equipment.id)
.notNull(),

outboundLoadId: uuid('outbound_load_id').references(() => outboundLoads.id),
loadStatus: outboundLoadStatusEnum('load_status').notNull().default('Unassigned'),

createdOn: timestamp('created_on', {
mode: 'date',
withTimezone: true,
}).defaultNow(),

updatedOn: timestamp('updated_on', {
mode: 'date',
withTimezone: true,
}).defaultNow(),
},
(t) => ({
jobIdIdx: index().on(t.jobId),
uniqueEquipmentId: uniqueIndex().on(t.jobId, t.equipmentId),
}),
);

export const jobSupportEquipmentRelations = relations(jobSupportEquipment, ({ one, many }) => ({
job: one(jobs, {
fields: [jobSupportEquipment.jobId],
references: [jobs.id],
}),
equipment: one(equipment, {
fields: [jobSupportEquipment.equipmentId],
references: [equipment.id],
}),
outboundLoad: one(outboundLoads, {
fields: [jobSupportEquipment.outboundLoadId],
references: [outboundLoads.id],
}),
}));
export const jobSupportEquipment = pgTable(
'job_support_equipment',
{
id: uuid('id').primaryKey().defaultRandom(),
jobId: uuid('job_id')
.references(() => jobs.id)
.notNull(),
equipmentId: uuid('equipment_id')
.references(() => equipment.id)
.notNull(),

outboundLoadId: uuid('outbound_load_id').references(() => outboundLoads.id),
loadStatus: outboundLoadStatusEnum('load_status').notNull().default('Unassigned'),

createdOn: timestamp('created_on', {
mode: 'date',
withTimezone: true,
}).defaultNow(),

updatedOn: timestamp('updated_on', {
mode: 'date',
withTimezone: true,
}).defaultNow(),
},
(t) => ({
jobIdIdx: index().on(t.jobId),
uniqueEquipmentId: uniqueIndex().on(t.jobId, t.equipmentId),
}),
);

export const jobSupportEquipmentRelations = relations(jobSupportEquipment, ({ one, many }) => ({
job: one(jobs, {
fields: [jobSupportEquipment.jobId],
references: [jobs.id],
}),
equipment: one(equipment, {
fields: [jobSupportEquipment.equipmentId],
references: [equipment.id],
}),
outboundLoad: one(outboundLoads, {
fields: [jobSupportEquipment.outboundLoadId],
references: [outboundLoads.id],
}),
}));
19 replies
DTDrizzle Team
Created by tomeverson on 8/18/2023 in #help
ERROR: operator does not exist: uuid = character varying
export const outboundLoads = pgTable(
'outbound_loads',
{
id: uuid('id').primaryKey().defaultRandom(),
loadNumber: integer('load_number').notNull(),

organizationId: uuid('organization_id')
.references(() => organizations.id)
.notNull(),

jobId: uuid('job_id')
.references(() => jobs.id)
.notNull(),

trailerClassId: uuid('trailer_class_id')
.references(() => vehicleTypeClasses.id)
.notNull(),
trailerId: uuid('trailer_id').references(() => vehicles.id),

loadStatus: outboundLoadStatusEnum('load_status').notNull().default('Unassigned'),

name: varchar('name'),
description: varchar('description'),

createdOn: timestamp('created_on', {
mode: 'date',
withTimezone: true,
}).defaultNow(),

updatedOn: timestamp('updated_on', {
mode: 'date',
withTimezone: true,
}).defaultNow(),
},
(t) => ({
jobIdIdx: index().on(t.jobId),
statusIdx: index().on(t.loadStatus),
}),
);

export const outboundLoadRelations = relations(outboundLoads, ({ one, many }) => ({
destinationAddress: one(addresses, {
fields: [outboundLoads.id],
references: [addresses.belongsTo],
}),
job: one(jobs, {
fields: [outboundLoads.jobId],
references: [jobs.id],
}),

trailerClass: one(vehicleTypeClasses, {
fields: [outboundLoads.trailerClassId],
references: [vehicleTypeClasses.id],
}),

trailer: one(vehicles, {
fields: [outboundLoads.trailerId],
references: [vehicles.id],
}),

supportEquipment: many(jobSupportEquipment),
supportVehicles: many(jobSupportVehicles),

lotPieces: many(lotPieces),
}));
export const outboundLoads = pgTable(
'outbound_loads',
{
id: uuid('id').primaryKey().defaultRandom(),
loadNumber: integer('load_number').notNull(),

organizationId: uuid('organization_id')
.references(() => organizations.id)
.notNull(),

jobId: uuid('job_id')
.references(() => jobs.id)
.notNull(),

trailerClassId: uuid('trailer_class_id')
.references(() => vehicleTypeClasses.id)
.notNull(),
trailerId: uuid('trailer_id').references(() => vehicles.id),

loadStatus: outboundLoadStatusEnum('load_status').notNull().default('Unassigned'),

name: varchar('name'),
description: varchar('description'),

createdOn: timestamp('created_on', {
mode: 'date',
withTimezone: true,
}).defaultNow(),

updatedOn: timestamp('updated_on', {
mode: 'date',
withTimezone: true,
}).defaultNow(),
},
(t) => ({
jobIdIdx: index().on(t.jobId),
statusIdx: index().on(t.loadStatus),
}),
);

export const outboundLoadRelations = relations(outboundLoads, ({ one, many }) => ({
destinationAddress: one(addresses, {
fields: [outboundLoads.id],
references: [addresses.belongsTo],
}),
job: one(jobs, {
fields: [outboundLoads.jobId],
references: [jobs.id],
}),

trailerClass: one(vehicleTypeClasses, {
fields: [outboundLoads.trailerClassId],
references: [vehicleTypeClasses.id],
}),

trailer: one(vehicles, {
fields: [outboundLoads.trailerId],
references: [vehicles.id],
}),

supportEquipment: many(jobSupportEquipment),
supportVehicles: many(jobSupportVehicles),

lotPieces: many(lotPieces),
}));
19 replies
DTDrizzle Team
Created by tomeverson on 8/18/2023 in #help
ERROR: operator does not exist: uuid = character varying
could it possibly be that in my one to many relationship - the many side has a uuid field but that field can potentially be null - (i.e. if an outbound load has not been assigned to a job support equipment) (sending code in follow up message)
19 replies
DTDrizzle Team
Created by tomeverson on 8/18/2023 in #help
ERROR: operator does not exist: uuid = character varying
any idea if theres a way to see which column has the mismatch in the error? i have some fairly complex relations so hard to track it down
19 replies
DTDrizzle Team
Created by tomeverson on 8/18/2023 in #help
ERROR: operator does not exist: uuid = character varying
thank you! - now gotta find where i have the mismatch
19 replies
DTDrizzle Team
Created by tomeverson on 8/18/2023 in #help
ERROR: operator does not exist: uuid = character varying
anyone know what was going on with this? all the sudden starting to see this no clue what the error is referencing
19 replies
DTDrizzle Team
Created by Liam on 7/8/2023 in #help
Drizzle-zod Include Relations
Can you share it?
10 replies
DTDrizzle Team
Created by iolyd on 1/20/2024 in #help
Less verbose generic types for helper functions
wow this looks great! thank you for this!
10 replies
DTDrizzle Team
Created by iolyd on 1/20/2024 in #help
Less verbose generic types for helper functions
did either of you ever get a decent set of wrappers working?
10 replies
DTDrizzle Team
Created by Suji on 1/27/2024 in #help
Help with types relational query function
No description
28 replies
DTDrizzle Team
Created by Suji on 1/27/2024 in #help
Help with types relational query function
okay - so i had to import both the db and the spread schema object from the db file instead of building the same schema spread object in the consuming paginatedQuery file so doing this db.ts
import * as allSchemas from '@server/db/schema';
import { drizzle } from 'drizzle-orm/postgres-js';
import { Client } from 'pg';

const connectionString = import.meta.env.VITE_DB_URL;

if (!connectionString) {
throw new Error('DB credentials error');
}

const client = new Client({ connectionString });
await client.connect();

export const schema = { ...allSchemas };

export const db = drizzle(client, { schema });
import * as allSchemas from '@server/db/schema';
import { drizzle } from 'drizzle-orm/postgres-js';
import { Client } from 'pg';

const connectionString = import.meta.env.VITE_DB_URL;

if (!connectionString) {
throw new Error('DB credentials error');
}

const client = new Client({ connectionString });
await client.connect();

export const schema = { ...allSchemas };

export const db = drizzle(client, { schema });
and making sure I import schema from db and not to just rebuild the object by importing and spreading again
import { db, schema } from '@server/db';

... other code

async function paginatedQuery<
U extends keyof ExtractTablesWithRelations<typeof schema>,
TableRelations extends IncludeRelation<U>,
>(
table: U,
{
with: queryWith,
}: {
with: TableRelations;
},
) {
const data = await db.query[table].findMany({
with: queryWith,
});

return data;
}
import { db, schema } from '@server/db';

... other code

async function paginatedQuery<
U extends keyof ExtractTablesWithRelations<typeof schema>,
TableRelations extends IncludeRelation<U>,
>(
table: U,
{
with: queryWith,
}: {
with: TableRelations;
},
) {
const data = await db.query[table].findMany({
with: queryWith,
});

return data;
}
28 replies
DTDrizzle Team
Created by Suji on 1/27/2024 in #help
Help with types relational query function
hahah sorry just rambling in here incase someone stumbles upon this later - so the spread syntax seemed to fix the issue however that required the db being defined in the same file as the paginatedQuery function... if i import the db i get the with error again
28 replies
DTDrizzle Team
Created by Suji on 1/27/2024 in #help
Help with types relational query function
okay looks like if i spread the * as into another object this might fix the problem but curious what the difference is - i know the * as is a namespace import but i thought it was identical to an object
28 replies
DTDrizzle Team
Created by Suji on 1/27/2024 in #help
Help with types relational query function
just to go even further incase my schema definitions were not setup correct - i created a testDirectory with a barrel file exporting only the schemas you defined in your playground. Importing with * as breaks but importing each table individually and building the schema object seems to work - very confused
28 replies
DTDrizzle Team
Created by Suji on 1/27/2024 in #help
Help with types relational query function
yeah i just refactored and made sure i only have pgTables and relations exporting out of my schema files - can not get the barrel file to work and i really don't want to individually import my tables and relations from 15 different files just to build a const schema = {locations, locationsRelations....... object for all my exports
28 replies
DTDrizzle Team
Created by Suji on 1/27/2024 in #help
Help with types relational query function
when I import schema like so import * as schema from '@server/db/schema/addresses'; i get that error however if i do this
import { addresses } from '@server/db/schema/addresses';
const schema = { addresses };
import { addresses } from '@server/db/schema/addresses';
const schema = { addresses };
it works so im curious if it has something to do with barrel files and import * as
28 replies
DTDrizzle Team
Created by Suji on 1/27/2024 in #help
Help with types relational query function
okay i think it has something to do with importing my schema definition from a barrel file
28 replies