Skip to content

Commit a2328f2

Browse files
committed
🚧 wip
1 parent 88dd60a commit a2328f2

13 files changed

Lines changed: 82 additions & 246 deletions

‎lib/abilityBuilder.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ export const createAbilityBuilder = <
418418
get where() {
419419
return filters?.where
420420
? relationsFilterToSQL(
421-
tableSchema as any,
421+
tableSchema.foundRelation.table,
422422
filters.where,
423423
)
424424
: undefined;
@@ -490,7 +490,7 @@ export const createAbilityBuilder = <
490490
get where() {
491491
return filters?.where
492492
? relationsFilterToSQL(
493-
tableSchema as any,
493+
tableSchema.foundRelation,
494494
filters.where,
495495
)
496496
: undefined;

‎lib/helpers/mergeFilters.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function mergeFilters<
4242

4343
const limit =
4444
filterA?.limit || filterB?.limit
45-
? Math.min(filterA?.limit ?? Infinity, filterB?.limit ?? Infinity)
45+
? Math.max(filterA?.limit ?? -Infinity, filterB?.limit ?? -Infinity)
4646
: undefined;
4747

4848
const offset =
@@ -55,8 +55,6 @@ export function mergeFilters<
5555
? toMerged(filterA?.with ?? {}, filterB?.with ?? {})
5656
: undefined;
5757

58-
console.log({ limit, offset });
59-
6058
return {
6159
where,
6260
columns,

‎lib/helpers/tableHelpers.ts‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { Column } from "drizzle-orm";
1+
import type { Column, Many, One } from "drizzle-orm";
2+
import { primaryKey } from "drizzle-orm/gel-core";
23
import type {
34
DrizzleInstance,
45
DrizzleTableSchema,
@@ -8,6 +9,7 @@ import { RumbleError } from "../types/rumbleError";
89
const drizzleNameSymbol = Symbol.for("drizzle:Name");
910
const drizzleOriginalNameSymbol = Symbol.for("drizzle:OriginalName");
1011
const drizzleBaseNameSymbol = Symbol.for("drizzle:BaseName");
12+
const drizzleColumnsSymbol = Symbol.for("drizzle:Columns");
1113

1214
export function tableHelper<
1315
DB extends DrizzleInstance,
@@ -46,9 +48,18 @@ export function tableHelper<
4648
throw new RumbleError(`Could not find schema for ${JSON.stringify(table)}`);
4749
}
4850

49-
foundSchema.relations = foundRelation.relations;
51+
// console.log(foundRelation );
52+
// console.log("-----");
5053

51-
return foundSchema as unknown as Omit<typeof foundSchema, "columns"> & {
52-
columns: Record<string, Column>;
54+
return {
55+
columns: foundSchema.columns,
56+
primaryKey: foundSchema.primaryKey,
57+
relations: (foundRelation as any).relations as {
58+
[key: string]: One<any, any> | Many<any>;
59+
},
60+
dbName: foundSchema.dbName,
61+
tsName: foundSchema.tsName,
62+
foundSchema,
63+
foundRelation,
5364
};
5465
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
CREATE TABLE `comments_table` (
2+
`id` text PRIMARY KEY NOT NULL,
3+
`text` text(256),
4+
`published` integer,
5+
`someNumber` numeric DEFAULT 0,
6+
`post_id` text,
7+
`owner_id` text NOT NULL,
8+
FOREIGN KEY (`post_id`) REFERENCES `posts_table`(`id`) ON UPDATE no action ON DELETE cascade,
9+
FOREIGN KEY (`owner_id`) REFERENCES `users_table`(`id`) ON UPDATE no action ON DELETE cascade
10+
);
11+
--> statement-breakpoint
12+
CREATE TABLE `posts_table` (
13+
`id` text PRIMARY KEY NOT NULL,
14+
`text` text,
15+
`title` text,
16+
`owner_id` text,
17+
FOREIGN KEY (`owner_id`) REFERENCES `users_table`(`id`) ON UPDATE no action ON DELETE cascade
18+
);
19+
--> statement-breakpoint
20+
CREATE TABLE `users_table` (
21+
`id` text PRIMARY KEY NOT NULL,
22+
`first_name` text,
23+
`last_name` text,
24+
`email` text NOT NULL
25+
);

‎test/drizzle/0000_robust_red_shift.sql‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎test/drizzle/0001_adorable_norman_osborn.sql‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎test/drizzle/meta/0000_snapshot.json‎

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"version": "6",
33
"dialect": "sqlite",
4-
"id": "9cc27506-c627-4568-aa30-5b60a2498e72",
4+
"id": "6a8f1655-63b9-47e2-8d31-b41a2e0062e9",
55
"prevId": "00000000-0000-0000-0000-000000000000",
66
"tables": {
7-
"comments": {
8-
"name": "comments",
7+
"comments_table": {
8+
"name": "comments_table",
99
"columns": {
1010
"id": {
1111
"name": "id",
@@ -28,6 +28,14 @@
2828
"notNull": false,
2929
"autoincrement": false
3030
},
31+
"someNumber": {
32+
"name": "someNumber",
33+
"type": "numeric",
34+
"primaryKey": false,
35+
"notNull": false,
36+
"autoincrement": false,
37+
"default": 0
38+
},
3139
"post_id": {
3240
"name": "post_id",
3341
"type": "text",
@@ -45,19 +53,19 @@
4553
},
4654
"indexes": {},
4755
"foreignKeys": {
48-
"comments_post_id_posts_id_fk": {
49-
"name": "comments_post_id_posts_id_fk",
50-
"tableFrom": "comments",
51-
"tableTo": "posts",
56+
"comments_table_post_id_posts_table_id_fk": {
57+
"name": "comments_table_post_id_posts_table_id_fk",
58+
"tableFrom": "comments_table",
59+
"tableTo": "posts_table",
5260
"columnsFrom": ["post_id"],
5361
"columnsTo": ["id"],
5462
"onDelete": "cascade",
5563
"onUpdate": "no action"
5664
},
57-
"comments_owner_id_users_id_fk": {
58-
"name": "comments_owner_id_users_id_fk",
59-
"tableFrom": "comments",
60-
"tableTo": "users",
65+
"comments_table_owner_id_users_table_id_fk": {
66+
"name": "comments_table_owner_id_users_table_id_fk",
67+
"tableFrom": "comments_table",
68+
"tableTo": "users_table",
6169
"columnsFrom": ["owner_id"],
6270
"columnsTo": ["id"],
6371
"onDelete": "cascade",
@@ -68,8 +76,8 @@
6876
"uniqueConstraints": {},
6977
"checkConstraints": {}
7078
},
71-
"posts": {
72-
"name": "posts",
79+
"posts_table": {
80+
"name": "posts_table",
7381
"columns": {
7482
"id": {
7583
"name": "id",
@@ -102,10 +110,10 @@
102110
},
103111
"indexes": {},
104112
"foreignKeys": {
105-
"posts_owner_id_users_id_fk": {
106-
"name": "posts_owner_id_users_id_fk",
107-
"tableFrom": "posts",
108-
"tableTo": "users",
113+
"posts_table_owner_id_users_table_id_fk": {
114+
"name": "posts_table_owner_id_users_table_id_fk",
115+
"tableFrom": "posts_table",
116+
"tableTo": "users_table",
109117
"columnsFrom": ["owner_id"],
110118
"columnsTo": ["id"],
111119
"onDelete": "cascade",
@@ -116,8 +124,8 @@
116124
"uniqueConstraints": {},
117125
"checkConstraints": {}
118126
},
119-
"users": {
120-
"name": "users",
127+
"users_table": {
128+
"name": "users_table",
121129
"columns": {
122130
"id": {
123131
"name": "id",

‎test/drizzle/meta/0001_snapshot.json‎

Lines changed: 0 additions & 176 deletions
This file was deleted.

0 commit comments

Comments
 (0)