@rebasepro/server-postgresql 0.0.1-canary.4d4fb3e → 0.0.1-canary.ca2cb6e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/src/collections/CollectionRegistry.d.ts +8 -0
- package/dist/common/src/util/entities.d.ts +22 -0
- package/dist/common/src/util/relations.d.ts +14 -4
- package/dist/common/src/util/resolutions.d.ts +1 -1
- package/dist/index.es.js +1254 -591
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1254 -591
- package/dist/index.umd.js.map +1 -1
- package/dist/server-postgresql/src/PostgresBackendDriver.d.ts +17 -29
- package/dist/server-postgresql/src/auth/services.d.ts +7 -3
- package/dist/server-postgresql/src/collections/PostgresCollectionRegistry.d.ts +1 -1
- package/dist/server-postgresql/src/connection.d.ts +34 -1
- package/dist/server-postgresql/src/data-transformer.d.ts +26 -4
- package/dist/server-postgresql/src/databasePoolManager.d.ts +2 -2
- package/dist/server-postgresql/src/schema/auth-schema.d.ts +139 -38
- package/dist/server-postgresql/src/schema/doctor-cli.d.ts +2 -0
- package/dist/server-postgresql/src/schema/doctor.d.ts +43 -0
- package/dist/server-postgresql/src/schema/generate-drizzle-schema-logic.d.ts +1 -1
- package/dist/server-postgresql/src/schema/test-schema.d.ts +24 -0
- package/dist/server-postgresql/src/services/EntityFetchService.d.ts +22 -8
- package/dist/server-postgresql/src/services/EntityPersistService.d.ts +1 -1
- package/dist/server-postgresql/src/services/RelationService.d.ts +11 -5
- package/dist/server-postgresql/src/services/entity-helpers.d.ts +16 -2
- package/dist/server-postgresql/src/services/entityService.d.ts +8 -6
- package/dist/server-postgresql/src/services/realtimeService.d.ts +2 -0
- package/dist/server-postgresql/src/utils/drizzle-conditions.d.ts +2 -2
- package/dist/types/src/controllers/auth.d.ts +2 -0
- package/dist/types/src/controllers/client.d.ts +119 -7
- package/dist/types/src/controllers/collection_registry.d.ts +4 -3
- package/dist/types/src/controllers/customization_controller.d.ts +7 -1
- package/dist/types/src/controllers/data.d.ts +34 -7
- package/dist/types/src/controllers/data_driver.d.ts +20 -28
- package/dist/types/src/controllers/database_admin.d.ts +2 -2
- package/dist/types/src/controllers/email.d.ts +34 -0
- package/dist/types/src/controllers/index.d.ts +1 -0
- package/dist/types/src/controllers/local_config_persistence.d.ts +4 -4
- package/dist/types/src/controllers/navigation.d.ts +5 -5
- package/dist/types/src/controllers/registry.d.ts +6 -3
- package/dist/types/src/controllers/side_entity_controller.d.ts +7 -6
- package/dist/types/src/controllers/storage.d.ts +24 -26
- package/dist/types/src/rebase_context.d.ts +8 -4
- package/dist/types/src/types/backend.d.ts +4 -1
- package/dist/types/src/types/builders.d.ts +5 -4
- package/dist/types/src/types/chips.d.ts +1 -1
- package/dist/types/src/types/collections.d.ts +169 -125
- package/dist/types/src/types/cron.d.ts +102 -0
- package/dist/types/src/types/data_source.d.ts +1 -1
- package/dist/types/src/types/entity_actions.d.ts +8 -8
- package/dist/types/src/types/entity_callbacks.d.ts +15 -15
- package/dist/types/src/types/entity_link_builder.d.ts +1 -1
- package/dist/types/src/types/entity_overrides.d.ts +2 -1
- package/dist/types/src/types/entity_views.d.ts +8 -8
- package/dist/types/src/types/export_import.d.ts +3 -3
- package/dist/types/src/types/index.d.ts +1 -0
- package/dist/types/src/types/plugins.d.ts +72 -18
- package/dist/types/src/types/properties.d.ts +118 -33
- package/dist/types/src/types/relations.d.ts +1 -1
- package/dist/types/src/types/slots.d.ts +30 -6
- package/dist/types/src/types/translations.d.ts +44 -0
- package/dist/types/src/types/user_management_delegate.d.ts +1 -0
- package/drizzle-test/0000_woozy_junta.sql +6 -0
- package/drizzle-test/0001_youthful_arachne.sql +1 -0
- package/drizzle-test/0002_lively_dragon_lord.sql +2 -0
- package/drizzle-test/0003_mean_king_cobra.sql +2 -0
- package/drizzle-test/meta/0000_snapshot.json +47 -0
- package/drizzle-test/meta/0001_snapshot.json +48 -0
- package/drizzle-test/meta/0002_snapshot.json +38 -0
- package/drizzle-test/meta/0003_snapshot.json +48 -0
- package/drizzle-test/meta/_journal.json +34 -0
- package/drizzle-test-out/0000_tan_trauma.sql +6 -0
- package/drizzle-test-out/0001_rapid_drax.sql +1 -0
- package/drizzle-test-out/meta/0000_snapshot.json +44 -0
- package/drizzle-test-out/meta/0001_snapshot.json +54 -0
- package/drizzle-test-out/meta/_journal.json +20 -0
- package/drizzle.test.config.ts +10 -0
- package/package.json +88 -89
- package/scratch.ts +41 -0
- package/src/PostgresBackendDriver.ts +63 -79
- package/src/PostgresBootstrapper.ts +7 -8
- package/src/auth/ensure-tables.ts +158 -86
- package/src/auth/services.ts +109 -50
- package/src/cli.ts +259 -16
- package/src/collections/PostgresCollectionRegistry.ts +6 -6
- package/src/connection.ts +70 -48
- package/src/data-transformer.ts +155 -116
- package/src/databasePoolManager.ts +6 -5
- package/src/history/HistoryService.ts +3 -12
- package/src/interfaces.ts +3 -3
- package/src/schema/auth-schema.ts +26 -3
- package/src/schema/doctor-cli.ts +47 -0
- package/src/schema/doctor.ts +595 -0
- package/src/schema/generate-drizzle-schema-logic.ts +204 -57
- package/src/schema/generate-drizzle-schema.ts +6 -6
- package/src/schema/test-schema.ts +11 -0
- package/src/services/BranchService.ts +5 -5
- package/src/services/EntityFetchService.ts +317 -188
- package/src/services/EntityPersistService.ts +15 -17
- package/src/services/RelationService.ts +299 -37
- package/src/services/entity-helpers.ts +39 -13
- package/src/services/entityService.ts +11 -9
- package/src/services/realtimeService.ts +58 -29
- package/src/utils/drizzle-conditions.ts +25 -24
- package/src/websocket.ts +52 -21
- package/test/auth-services.test.ts +131 -39
- package/test/batch-many-to-many-regression.test.ts +573 -0
- package/test/branchService.test.ts +22 -12
- package/test/data-transformer-hardening.test.ts +417 -0
- package/test/data-transformer.test.ts +175 -0
- package/test/doctor.test.ts +182 -0
- package/test/entityService.errors.test.ts +31 -16
- package/test/entityService.relations.test.ts +155 -59
- package/test/entityService.subcollection-search.test.ts +107 -57
- package/test/entityService.test.ts +105 -47
- package/test/generate-drizzle-schema.test.ts +262 -69
- package/test/historyService.test.ts +31 -16
- package/test/n-plus-one-regression.test.ts +314 -0
- package/test/postgresDataDriver.test.ts +260 -168
- package/test/realtimeService.test.ts +70 -39
- package/test/relation-pipeline-gaps.test.ts +637 -0
- package/test/relations.test.ts +492 -39
- package/test-drizzle-bug.ts +18 -0
- package/test-drizzle-out/0000_cultured_freak.sql +7 -0
- package/test-drizzle-out/0001_tiresome_professor_monster.sql +1 -0
- package/test-drizzle-out/meta/0000_snapshot.json +55 -0
- package/test-drizzle-out/meta/0001_snapshot.json +63 -0
- package/test-drizzle-out/meta/_journal.json +20 -0
- package/test-drizzle-prompt.sh +2 -0
- package/test-policy-prompt.sh +3 -0
- package/test-programmatic.ts +30 -0
- package/test-programmatic2.ts +59 -0
- package/test-schema-no-policies.ts +12 -0
- package/test_drizzle_mock.js +2 -2
- package/test_find_changed.mjs +3 -1
- package/test_hash.js +14 -0
- package/tsconfig.json +1 -1
- package/vite.config.ts +5 -5
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "ef1380c9-de61-4080-98b0-f790a94d4384",
|
|
3
|
+
"prevId": "00000000-0000-0000-0000-000000000000",
|
|
4
|
+
"version": "7",
|
|
5
|
+
"dialect": "postgresql",
|
|
6
|
+
"tables": {
|
|
7
|
+
"public.users": {
|
|
8
|
+
"name": "users",
|
|
9
|
+
"schema": "",
|
|
10
|
+
"columns": {
|
|
11
|
+
"id": {
|
|
12
|
+
"name": "id",
|
|
13
|
+
"type": "integer",
|
|
14
|
+
"primaryKey": true,
|
|
15
|
+
"notNull": true
|
|
16
|
+
},
|
|
17
|
+
"name": {
|
|
18
|
+
"name": "name",
|
|
19
|
+
"type": "varchar",
|
|
20
|
+
"primaryKey": false,
|
|
21
|
+
"notNull": false
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"indexes": {},
|
|
25
|
+
"foreignKeys": {},
|
|
26
|
+
"compositePrimaryKeys": {},
|
|
27
|
+
"uniqueConstraints": {},
|
|
28
|
+
"policies": {},
|
|
29
|
+
"checkConstraints": {},
|
|
30
|
+
"isRLSEnabled": true
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"enums": {},
|
|
34
|
+
"schemas": {},
|
|
35
|
+
"sequences": {},
|
|
36
|
+
"roles": {},
|
|
37
|
+
"policies": {},
|
|
38
|
+
"views": {},
|
|
39
|
+
"_meta": {
|
|
40
|
+
"columns": {},
|
|
41
|
+
"schemas": {},
|
|
42
|
+
"tables": {}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "d98375cd-115c-4ec6-ae56-cbcc39ea8b13",
|
|
3
|
+
"prevId": "ef1380c9-de61-4080-98b0-f790a94d4384",
|
|
4
|
+
"version": "7",
|
|
5
|
+
"dialect": "postgresql",
|
|
6
|
+
"tables": {
|
|
7
|
+
"public.users": {
|
|
8
|
+
"name": "users",
|
|
9
|
+
"schema": "",
|
|
10
|
+
"columns": {
|
|
11
|
+
"id": {
|
|
12
|
+
"name": "id",
|
|
13
|
+
"type": "integer",
|
|
14
|
+
"primaryKey": true,
|
|
15
|
+
"notNull": true
|
|
16
|
+
},
|
|
17
|
+
"name": {
|
|
18
|
+
"name": "name",
|
|
19
|
+
"type": "varchar",
|
|
20
|
+
"primaryKey": false,
|
|
21
|
+
"notNull": false
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"indexes": {},
|
|
25
|
+
"foreignKeys": {},
|
|
26
|
+
"compositePrimaryKeys": {},
|
|
27
|
+
"uniqueConstraints": {},
|
|
28
|
+
"policies": {
|
|
29
|
+
"test_policy": {
|
|
30
|
+
"name": "test_policy",
|
|
31
|
+
"as": "PERMISSIVE",
|
|
32
|
+
"for": "ALL",
|
|
33
|
+
"to": [
|
|
34
|
+
"public"
|
|
35
|
+
],
|
|
36
|
+
"using": "true"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"checkConstraints": {},
|
|
40
|
+
"isRLSEnabled": true
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"enums": {},
|
|
44
|
+
"schemas": {},
|
|
45
|
+
"sequences": {},
|
|
46
|
+
"roles": {},
|
|
47
|
+
"policies": {},
|
|
48
|
+
"views": {},
|
|
49
|
+
"_meta": {
|
|
50
|
+
"columns": {},
|
|
51
|
+
"schemas": {},
|
|
52
|
+
"tables": {}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "7",
|
|
3
|
+
"dialect": "postgresql",
|
|
4
|
+
"entries": [
|
|
5
|
+
{
|
|
6
|
+
"idx": 0,
|
|
7
|
+
"version": "7",
|
|
8
|
+
"when": 1777413439093,
|
|
9
|
+
"tag": "0000_tan_trauma",
|
|
10
|
+
"breakpoints": true
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"idx": 1,
|
|
14
|
+
"version": "7",
|
|
15
|
+
"when": 1777413457223,
|
|
16
|
+
"tag": "0001_rapid_drax",
|
|
17
|
+
"breakpoints": true
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineConfig } from "drizzle-kit";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
schema: "./test-schema-no-policies.ts",
|
|
5
|
+
out: "./drizzle-test-out",
|
|
6
|
+
dialect: "postgresql",
|
|
7
|
+
dbCredentials: {
|
|
8
|
+
url: process.env.DATABASE_URL || "postgres://postgres:postgres@localhost:5432/postgres"
|
|
9
|
+
}
|
|
10
|
+
});
|
package/package.json
CHANGED
|
@@ -1,93 +1,92 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
"name": "@rebasepro/server-postgresql",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1-canary.ca2cb6e",
|
|
5
|
+
"description": "PostgreSQL data source backend implementation for Rebase with Drizzle ORM",
|
|
6
|
+
"funding": {
|
|
7
|
+
"url": "https://github.com/sponsors/rebaseco"
|
|
8
|
+
},
|
|
9
|
+
"author": "Rebase",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/rebasepro/rebase.git",
|
|
14
|
+
"directory": "packages/server-postgresql"
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/index.umd.js",
|
|
17
|
+
"module": "./dist/index.es.js",
|
|
18
|
+
"types": "./dist/server-postgresql/src/index.d.ts",
|
|
19
|
+
"source": "src/index.ts",
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=20"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"cms",
|
|
25
|
+
"admin",
|
|
26
|
+
"postgresql",
|
|
27
|
+
"database",
|
|
28
|
+
"drizzle",
|
|
29
|
+
"backend",
|
|
30
|
+
"rebase"
|
|
31
|
+
],
|
|
32
|
+
"jest": {
|
|
33
|
+
"transform": {
|
|
34
|
+
"^.+\\.tsx?$": "ts-jest"
|
|
8
35
|
},
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"module": "./dist/index.es.js",
|
|
18
|
-
"types": "./dist/server-postgresql/src/index.d.ts",
|
|
19
|
-
"source": "src/index.ts",
|
|
20
|
-
"engines": {
|
|
21
|
-
"node": ">=20"
|
|
22
|
-
},
|
|
23
|
-
"keywords": [
|
|
24
|
-
"cms",
|
|
25
|
-
"admin",
|
|
26
|
-
"postgresql",
|
|
27
|
-
"database",
|
|
28
|
-
"drizzle",
|
|
29
|
-
"backend",
|
|
30
|
-
"rebase"
|
|
36
|
+
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
|
|
37
|
+
"moduleFileExtensions": [
|
|
38
|
+
"ts",
|
|
39
|
+
"tsx",
|
|
40
|
+
"js",
|
|
41
|
+
"jsx",
|
|
42
|
+
"json",
|
|
43
|
+
"node"
|
|
31
44
|
],
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"test:lint": "eslint \"src/**\" --quiet",
|
|
37
|
-
"test": "jest --passWithNoTests",
|
|
38
|
-
"clean": "rm -rf dist && find ./src -name '*.js' -type f | xargs rm -f"
|
|
39
|
-
},
|
|
40
|
-
"jest": {
|
|
41
|
-
"transform": {
|
|
42
|
-
"^.+\\.tsx?$": "ts-jest"
|
|
43
|
-
},
|
|
44
|
-
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
|
|
45
|
-
"moduleFileExtensions": [
|
|
46
|
-
"ts",
|
|
47
|
-
"tsx",
|
|
48
|
-
"js",
|
|
49
|
-
"jsx",
|
|
50
|
-
"json",
|
|
51
|
-
"node"
|
|
52
|
-
],
|
|
53
|
-
"moduleNameMapper": {
|
|
54
|
-
"^@rebasepro/common$": "<rootDir>/../common/src/index.ts",
|
|
55
|
-
"^@rebasepro/types$": "<rootDir>/../types/src/index.ts",
|
|
56
|
-
"^@rebasepro/utils$": "<rootDir>/../utils/src/index.ts"
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
"exports": {
|
|
60
|
-
".": {
|
|
61
|
-
"types": "./dist/server-postgresql/src/index.d.ts",
|
|
62
|
-
"development": "./src/index.ts",
|
|
63
|
-
"import": "./dist/index.es.js",
|
|
64
|
-
"require": "./dist/index.umd.js"
|
|
65
|
-
},
|
|
66
|
-
"./package.json": "./package.json"
|
|
67
|
-
},
|
|
68
|
-
"dependencies": {
|
|
69
|
-
"@rebasepro/common": "0.0.1-canary.4d4fb3e",
|
|
70
|
-
"@rebasepro/server-core": "0.0.1-canary.4d4fb3e",
|
|
71
|
-
"@rebasepro/types": "0.0.1-canary.4d4fb3e",
|
|
72
|
-
"@rebasepro/utils": "0.0.1-canary.4d4fb3e",
|
|
73
|
-
"arg": "^5.0.2",
|
|
74
|
-
"chalk": "^4.1.2",
|
|
75
|
-
"drizzle-orm": "^0.44.4",
|
|
76
|
-
"execa": "^4.1.0",
|
|
77
|
-
"pg": "^8.11.3"
|
|
78
|
-
},
|
|
79
|
-
"devDependencies": {
|
|
80
|
-
"@types/jest": "^29.5.14",
|
|
81
|
-
"@types/node": "^20.10.5",
|
|
82
|
-
"@types/pg": "^8.6.5",
|
|
83
|
-
"drizzle-kit": "^0.31.4",
|
|
84
|
-
"jest": "^29.7.0",
|
|
85
|
-
"ts-jest": "^29.4.5",
|
|
86
|
-
"typescript": "^5.0.0",
|
|
87
|
-
"vite": "^5.0.0"
|
|
88
|
-
},
|
|
89
|
-
"gitHead": "71bcef3c51a458cd054f7924cc18efbbe515dcc8",
|
|
90
|
-
"publishConfig": {
|
|
91
|
-
"access": "public"
|
|
45
|
+
"moduleNameMapper": {
|
|
46
|
+
"^@rebasepro/common$": "<rootDir>/../common/src/index.ts",
|
|
47
|
+
"^@rebasepro/types$": "<rootDir>/../types/src/index.ts",
|
|
48
|
+
"^@rebasepro/utils$": "<rootDir>/../utils/src/index.ts"
|
|
92
49
|
}
|
|
93
|
-
}
|
|
50
|
+
},
|
|
51
|
+
"exports": {
|
|
52
|
+
".": {
|
|
53
|
+
"types": "./dist/server-postgresql/src/index.d.ts",
|
|
54
|
+
"development": "./src/index.ts",
|
|
55
|
+
"import": "./dist/index.es.js",
|
|
56
|
+
"require": "./dist/index.umd.js"
|
|
57
|
+
},
|
|
58
|
+
"./package.json": "./package.json"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"arg": "^5.0.2",
|
|
62
|
+
"chalk": "^4.1.2",
|
|
63
|
+
"drizzle-orm": "^0.44.4",
|
|
64
|
+
"execa": "^4.1.0",
|
|
65
|
+
"pg": "^8.11.3",
|
|
66
|
+
"@rebasepro/common": "0.0.1-canary.ca2cb6e",
|
|
67
|
+
"@rebasepro/utils": "0.0.1-canary.ca2cb6e",
|
|
68
|
+
"@rebasepro/server-core": "0.0.1-canary.ca2cb6e",
|
|
69
|
+
"@rebasepro/types": "0.0.1-canary.ca2cb6e"
|
|
70
|
+
},
|
|
71
|
+
"devDependencies": {
|
|
72
|
+
"@types/jest": "^29.5.14",
|
|
73
|
+
"@types/node": "^20.10.5",
|
|
74
|
+
"@types/pg": "^8.6.5",
|
|
75
|
+
"drizzle-kit": "^0.31.4",
|
|
76
|
+
"jest": "^29.7.0",
|
|
77
|
+
"ts-jest": "^29.4.5",
|
|
78
|
+
"typescript": "^5.0.0",
|
|
79
|
+
"vite": "^5.0.0"
|
|
80
|
+
},
|
|
81
|
+
"gitHead": "d935eefa5aa8d1009a2398cfac2c1e4ee9aeb6b6",
|
|
82
|
+
"publishConfig": {
|
|
83
|
+
"access": "public"
|
|
84
|
+
},
|
|
85
|
+
"scripts": {
|
|
86
|
+
"watch": "vite build --watch",
|
|
87
|
+
"build": "vite build && tsc --emitDeclarationOnly -p tsconfig.prod.json",
|
|
88
|
+
"test:lint": "eslint \"src/**\" --quiet",
|
|
89
|
+
"test": "jest --passWithNoTests",
|
|
90
|
+
"clean": "rm -rf dist && find ./src -name '*.js' -type f | xargs rm -f"
|
|
91
|
+
}
|
|
92
|
+
}
|
package/scratch.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { pgTable, integer, varchar } from "drizzle-orm/pg-core";
|
|
2
|
+
import { eq } from "drizzle-orm";
|
|
3
|
+
import { drizzle } from "drizzle-orm/node-postgres";
|
|
4
|
+
import { Client } from "pg";
|
|
5
|
+
import { config } from "dotenv";
|
|
6
|
+
config({ path: "../../.env" });
|
|
7
|
+
|
|
8
|
+
const authors = pgTable("authors", {
|
|
9
|
+
id: integer("id").primaryKey(),
|
|
10
|
+
name: varchar("name")
|
|
11
|
+
});
|
|
12
|
+
const posts = pgTable("posts", {
|
|
13
|
+
id: integer("id").primaryKey(),
|
|
14
|
+
author_id: integer("author_id")
|
|
15
|
+
});
|
|
16
|
+
const profiles = pgTable("profiles", {
|
|
17
|
+
id: integer("id").primaryKey(),
|
|
18
|
+
author_id: integer("author_id")
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
async function main() {
|
|
22
|
+
const client = new Client({
|
|
23
|
+
connectionString: process.env.DATABASE_URL || "postgres://postgres:postgres@localhost:5432/postgres"
|
|
24
|
+
});
|
|
25
|
+
await client.connect();
|
|
26
|
+
const db = drizzle(client);
|
|
27
|
+
|
|
28
|
+
let query = db.select().from(posts);
|
|
29
|
+
// @ts-expect-error
|
|
30
|
+
query = query.innerJoin(authors, eq(posts.author_id, authors.id));
|
|
31
|
+
// @ts-expect-error
|
|
32
|
+
query = query.innerJoin(profiles, eq(authors.id, profiles.author_id));
|
|
33
|
+
|
|
34
|
+
const results = await query;
|
|
35
|
+
console.log("Drizzle Inner Join Results:");
|
|
36
|
+
console.log(JSON.stringify(results, null, 2));
|
|
37
|
+
|
|
38
|
+
await client.end();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
main().catch(console.error);
|