scape
scape
DTDrizzle Team
Created by outranker on 12/29/2024 in #help
why does `alias()` create a new table?
you can create separate file, e.g aliases.ts (which is not part of schema you export to drizzle.config.ts) and put them there
4 replies
DTDrizzle Team
Created by outranker on 12/29/2024 in #help
why does `alias()` create a new table?
you don't need to export it from the schema file, since each table exported from there will be generated in your migrations folder
4 replies
DTDrizzle Team
Created by manikandan on 12/28/2024 in #help
Is there any option to use Drizzle InferSelectModel value for annotating swagger response
what does it say?
7 replies
DTDrizzle Team
Created by manikandan on 12/28/2024 in #help
Is there any option to use Drizzle InferSelectModel value for annotating swagger response
It wants the javascript object itself, not the typescript type, you can try putting
import { getTableColumns } from "drizzle-orm";
...
({type: getTableColumns(users)})
import { getTableColumns } from "drizzle-orm";
...
({type: getTableColumns(users)})
7 replies
DTDrizzle Team
Created by .frag on 12/27/2024 in #help
ORM relation `where` does not exist in type
on the other hand, you can make it using select, fe
db.select()
.from(item)
.where(and(eq(item.id, id), eq(collection.userId, userId))
.innerJoin(collection, eq(collection.itemId, item.Id))
db.select()
.from(item)
.where(and(eq(item.id, id), eq(collection.userId, userId))
.innerJoin(collection, eq(collection.itemId, item.Id))
15 replies
DTDrizzle Team
Created by .frag on 12/27/2024 in #help
ORM relation `where` does not exist in type
as far as I know, nested where currently is not supported with queries
15 replies
DTDrizzle Team
Created by Baron_ThoughtEvolution on 12/21/2024 in #help
Unable to use db.query... functions
try doing this:
const db = drizzle(process.env.DATABASE_URL!, { schema })
const db = drizzle(process.env.DATABASE_URL!, { schema })
3 replies
DTDrizzle Team
Created by Tomato on 12/21/2024 in #help
Drizzle ORM - Query on the same file
No description
2 replies
DTDrizzle Team
Created by jack on 12/21/2024 in #help
[postgres] composite key does not result in constraint creation
Hmmm, I just went to github issues to see if someone already reported it. https://github.com/drizzle-team/drizzle-orm/issues/3805 In the comments, xorraxraxret suggests providing pk's via array, not via record. I've tried it on your table:
export const preferenceTable = pgTable(
"preference",
{
userId: uuidv7("group_id").notNull(),
defaultGroupId: uuidv7("default_group_id"),
},
({ userId, defaultGroupId }) => [
primaryKey({ columns: [userId, defaultGroupId] }),
],
);
export const preferenceTable = pgTable(
"preference",
{
userId: uuidv7("group_id").notNull(),
defaultGroupId: uuidv7("default_group_id"),
},
({ userId, defaultGroupId }) => [
primaryKey({ columns: [userId, defaultGroupId] }),
],
);
and it generated right schema:
CREATE TABLE "preference" (
"group_id" uuid NOT NULL,
"default_group_id" uuid,
CONSTRAINT "preference_group_id_default_group_id_pk" PRIMARY KEY("group_id","default_group_id")
);
CREATE TABLE "preference" (
"group_id" uuid NOT NULL,
"default_group_id" uuid,
CONSTRAINT "preference_group_id_default_group_id_pk" PRIMARY KEY("group_id","default_group_id")
);
So you can try doing this. Anyway, this is still a bug. Docs mention that you can provide a record of constrains, but this doesn't work
7 replies
DTDrizzle Team
Created by jack on 12/21/2024 in #help
[postgres] composite key does not result in constraint creation
In your case, you can modify generated sql, if you use migrations:
CREATE TABLE "preference" (
"group_id" uuid NOT NULL,
"default_group_id" uuid,
PRIMARY KEY("group_id","default_group_id")
);
CREATE TABLE "preference" (
"group_id" uuid NOT NULL,
"default_group_id" uuid,
PRIMARY KEY("group_id","default_group_id")
);
or you can just run the following sql saying add me a pk constraint to my table:
ALTER TABLE "preference" ADD CONSTRAINT "preference_pk" PRIMARY KEY("group_id","default_group_id");
ALTER TABLE "preference" ADD CONSTRAINT "preference_pk" PRIMARY KEY("group_id","default_group_id");
7 replies
DTDrizzle Team
Created by jack on 12/21/2024 in #help
[postgres] composite key does not result in constraint creation
I've tried to reproduce it and test it with others drizzle-kit versions down to 0.29.0. This is definitely a bug. Besides your schema, I've tried to reproduce the one, that is provided in the docs (https://orm.drizzle.team/docs/indexes-constraints#composite-primary-key) and it resulted not in the way as it's supposed to:
CREATE TABLE "book" (
"id" serial PRIMARY KEY NOT NULL,
"name" text
);
--> statement-breakpoint
CREATE TABLE "books_to_authors" (
"author_id" integer,
"book_id" integer
);
--> statement-breakpoint
CREATE TABLE "user" (
"id" serial PRIMARY KEY NOT NULL,
"name" text
);
CREATE TABLE "book" (
"id" serial PRIMARY KEY NOT NULL,
"name" text
);
--> statement-breakpoint
CREATE TABLE "books_to_authors" (
"author_id" integer,
"book_id" integer
);
--> statement-breakpoint
CREATE TABLE "user" (
"id" serial PRIMARY KEY NOT NULL,
"name" text
);
(no primary key constraint.) I will create an issue for that. Thank you for reporting.
7 replies
DTDrizzle Team
Created by N on 12/21/2024 in #help
Self referencing composite primary key table
results in:
[
{
id: "loc1",
orgId: "org1",
name: "Headquarters",
isLeaf: false,
parentId: null,
parentOrgId: null,
}, {
id: "loc5",
orgId: "org2",
name: "Regional HQ",
isLeaf: false,
parentId: null,
parentOrgId: null,
}
]
[
{
parentId: "loc1",
childrenIds: [ "loc2", "loc3" ],
}, {
parentId: "loc2",
childrenIds: [ "loc4" ],
}, {
parentId: "loc5",
childrenIds: [ "loc6" ],
}
]
[
{
id: "loc1",
orgId: "org1",
name: "Headquarters",
isLeaf: false,
parentId: null,
parentOrgId: null,
}, {
id: "loc5",
orgId: "org2",
name: "Regional HQ",
isLeaf: false,
parentId: null,
parentOrgId: null,
}
]
[
{
parentId: "loc1",
childrenIds: [ "loc2", "loc3" ],
}, {
parentId: "loc2",
childrenIds: [ "loc4" ],
}, {
parentId: "loc5",
childrenIds: [ "loc6" ],
}
]
4 replies
DTDrizzle Team
Created by N on 12/21/2024 in #help
Self referencing composite primary key table
Hi, can you provide the error you are getting? It seems like your schema is right, I've got it working on my machine. I also made a script to test it, and everything works:
const cozy = {
locations: [
{
id: "loc1",
orgId: "org1",
name: "Headquarters",
isLeaf: false,
parentId: null,
parentOrgId: null,
},
{
id: "loc2",
orgId: "org1",
name: "Branch Office 1",
isLeaf: false,
parentId: "loc1",
parentOrgId: "org1",
},
{
id: "loc3",
orgId: "org1",
name: "Branch Office 2",
isLeaf: false,
parentId: "loc1",
parentOrgId: "org1",
},
{
id: "loc4",
orgId: "org1",
name: "Storage Facility",
isLeaf: true,
parentId: "loc2",
parentOrgId: "org1",
},
{
id: "loc5",
orgId: "org2",
name: "Regional HQ",
isLeaf: false,
parentId: null,
parentOrgId: null,
},
{
id: "loc6",
orgId: "org2",
name: "Warehouse",
isLeaf: true,
parentId: "loc5",
parentOrgId: "org2",
},
],
};

await db
.insert(locations)
.values(cozy.locations)
.catch((err) => {
console.error(err);
process.exit(1);
});

const result = await db
.select()
.from(locations)
.where(isNull(locations.parentId));

console.log(result);

const childrenTable = aliasedTable(locations, "children");

const withChildren = await db
.select({
parentId: locations.id,
childrenIds: sql`array_agg(children.id)`,
})
.from(locations)
.innerJoin(
childrenTable,
and(
eq(childrenTable.parentId, locations.id),
eq(childrenTable.parentOrgId, locations.orgId),
),
)
.groupBy(locations.id);

console.log(withChildren);
const cozy = {
locations: [
{
id: "loc1",
orgId: "org1",
name: "Headquarters",
isLeaf: false,
parentId: null,
parentOrgId: null,
},
{
id: "loc2",
orgId: "org1",
name: "Branch Office 1",
isLeaf: false,
parentId: "loc1",
parentOrgId: "org1",
},
{
id: "loc3",
orgId: "org1",
name: "Branch Office 2",
isLeaf: false,
parentId: "loc1",
parentOrgId: "org1",
},
{
id: "loc4",
orgId: "org1",
name: "Storage Facility",
isLeaf: true,
parentId: "loc2",
parentOrgId: "org1",
},
{
id: "loc5",
orgId: "org2",
name: "Regional HQ",
isLeaf: false,
parentId: null,
parentOrgId: null,
},
{
id: "loc6",
orgId: "org2",
name: "Warehouse",
isLeaf: true,
parentId: "loc5",
parentOrgId: "org2",
},
],
};

await db
.insert(locations)
.values(cozy.locations)
.catch((err) => {
console.error(err);
process.exit(1);
});

const result = await db
.select()
.from(locations)
.where(isNull(locations.parentId));

console.log(result);

const childrenTable = aliasedTable(locations, "children");

const withChildren = await db
.select({
parentId: locations.id,
childrenIds: sql`array_agg(children.id)`,
})
.from(locations)
.innerJoin(
childrenTable,
and(
eq(childrenTable.parentId, locations.id),
eq(childrenTable.parentOrgId, locations.orgId),
),
)
.groupBy(locations.id);

console.log(withChildren);
4 replies
DTDrizzle Team
Created by Omesepelepe on 12/18/2024 in #help
"There is not enough information to infer relation" with many to many query
First, your schema is wrong. The intermediate table (the one, that links two tables for many-to-many relationship) can only have one to one reference with the ones it links. In your casez locationsToTagsRelations will have one(tags) & one(locations). Then, if you want to get all the locations with tags, you can use joins / with in findMany on your intermediate table
3 replies
DTDrizzle Team
Created by Zefty on 12/14/2024 in #help
Drizzle seed stuck and no info displayed
Should've created an issue. My bad. Will try to replicate rereproduce
11 replies
DTDrizzle Team
Created by Zefty on 12/14/2024 in #help
Drizzle seed stuck and no info displayed
Had exact same issue. You probably don't expose all relevant schema tables for drizzle seed. Make sure you provide tables that bloodPressure has fk's on.
11 replies
DTDrizzle Team
Created by Anas Badran on 12/14/2024 in #help
Build a complex query
I suppose you are struggling with making an aliased table for two similar joins Yes, it's definitely possible to do it with drizzle
import { aliasedTable, getTableColumns, and } from "drizzle-orm"

const ped1 = aliasedTable($postExtraData, 'ped1');
const ped2 = aliasedTable($postExtraData, 'ped2');

await db.select(getTableColumns($posts))
.from($posts)
.innerJoin(ped1, and(eq($posts.id, ped1.postId), and(eq(ped1.key, 'surah'), eq(ped1.value, '1'))))
.innerJoin(ped2, and(eq($posts.id, ped2.postId), and(eq(ped2.key, 'verse'), eq(ped1.value, '3'))))
import { aliasedTable, getTableColumns, and } from "drizzle-orm"

const ped1 = aliasedTable($postExtraData, 'ped1');
const ped2 = aliasedTable($postExtraData, 'ped2');

await db.select(getTableColumns($posts))
.from($posts)
.innerJoin(ped1, and(eq($posts.id, ped1.postId), and(eq(ped1.key, 'surah'), eq(ped1.value, '1'))))
.innerJoin(ped2, and(eq($posts.id, ped2.postId), and(eq(ped2.key, 'verse'), eq(ped1.value, '3'))))
more on aliases & selfjoins: https://orm.drizzle.team/docs/joins#aliases--selfjoins
4 replies
DTDrizzle Team
Created by yehtet804 on 12/9/2024 in #help
How to run drizzle studio in a docker container?
Hi, no, drizzle studio is a closed source product thus it's not available to run it locally.
2 replies
DTDrizzle Team
Created by WGW ☂ calldata.space on 12/8/2024 in #help
Drizzle GraphQL bug with SQLite JSON (Turso)
Hi! I think it's because the actual mapping between parsed / stringified json is made by the orm, meaning, if you do the query via:
db.select({links: collections.links}) .from(collections).orderBy(desc(collections.id))
db.select({links: collections.links}) .from(collections).orderBy(desc(collections.id))
you will get the parsed variant in the result. Since you are making the query in GraphQL Yoga, it returns the real value, just as it is stored in your sqlite database - as a text
8 replies
KPCKevin Powell - Community
Created by scape on 6/26/2023 in #front-end
UI implementation
Wolle, thank you for the suggestion. Ive already come up with the idea, and I also used grid. grid-template-column: 10rem (width of the sidebar) auto (but my main content also has max-width so it looks like it's in the middleof the screen) . And yes, for the tablet screen I will add a hamburger menu If it's allowed to leave links, here is where my implementation https://scape-portfolio.vercel.app/
3 replies