@xata.io/drizzle 0.0.0-alpha.vd49a3c13c6a49e2493777a49f0654c76deea43ee → 0.0.0-alpha.vd4c6670ecff885fe994910210681702accdcef2e

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.
@@ -1,6 +1,6 @@
1
1
  import { BaseClient, HostProvider, parseProviderString, XataApiClient } from '@xata.io/client';
2
2
  import 'dotenv/config';
3
- import { desc, DrizzleError, eq, gt, gte, or, placeholder, sql, TransactionRollbackError } from 'drizzle-orm';
3
+ import { desc, DrizzleError, eq, gt, gte, or, placeholder, sql } from 'drizzle-orm';
4
4
  import { Client } from 'pg';
5
5
  import { afterAll, afterEach, beforeAll, beforeEach, describe, expectTypeOf, test } from 'vitest';
6
6
  import { drizzle as drizzlePg, type XataDatabase } from '../src/pg';
@@ -51,7 +51,7 @@ function getDomain(host: HostProvider) {
51
51
  }
52
52
  }
53
53
 
54
- function getDrizzleClient(type: string, branch: string) {
54
+ function getDrizzleClient(type: string, database: string, branch: string) {
55
55
  if (type === 'http') {
56
56
  const xata = new BaseClient({
57
57
  apiKey,
@@ -76,19 +76,19 @@ function getDrizzleClient(type: string, branch: string) {
76
76
  }
77
77
  }
78
78
 
79
- describe.concurrent.each([{ type: 'pg' } /** , { type: 'http' }*/])('Drizzle $type', ({ type }) => {
79
+ describe.skip.concurrent.each([{ type: 'pg' }, { type: 'http' }])('Drizzle $type', ({ type }) => {
80
+ const dbName = `${database}-${type}`;
81
+
80
82
  beforeAll(async () => {
81
- await api.database.createDatabase({
82
- workspace,
83
- database,
84
- data: { region, branchName: 'main' },
85
- headers: { 'X-Features': 'feat-pgroll-migrations=1' }
83
+ await api.databases.createDatabase({
84
+ pathParams: { workspaceId: workspace, dbName },
85
+ body: { region, branchName: 'main', postgresEnabled: true }
86
86
  });
87
87
 
88
- await waitForReplication();
88
+ await waitForReplication(dbName);
89
89
 
90
90
  // For now, run the migrations via wire protocol
91
- const { client, db } = getDrizzleClient('pg', 'main');
91
+ const { client, db } = getDrizzleClient('pg', dbName, 'main');
92
92
  await client?.connect();
93
93
 
94
94
  await db.execute(
@@ -155,14 +155,17 @@ describe.concurrent.each([{ type: 'pg' } /** , { type: 'http' }*/])('Drizzle $ty
155
155
  });
156
156
 
157
157
  afterAll(async () => {
158
- await api.database.deleteDatabase({ workspace, database });
158
+ await api.databases.deleteDatabase({ pathParams: { workspaceId: workspace, dbName } });
159
159
  });
160
160
 
161
161
  beforeEach(async (ctx) => {
162
162
  ctx.branch = `test-${Math.random().toString(36).substring(7)}`;
163
- await api.branches.createBranch({ workspace, database, region, branch: ctx.branch, from: 'main' });
163
+ await api.branch.createBranch({
164
+ pathParams: { workspace, region, dbBranchName: `${dbName}:${ctx.branch}` },
165
+ body: { from: 'main' }
166
+ });
164
167
 
165
- const { db, client } = getDrizzleClient(type, ctx.branch);
168
+ const { db, client } = getDrizzleClient(type, dbName, ctx.branch);
166
169
  await client?.connect();
167
170
 
168
171
  ctx.db = db;
@@ -171,7 +174,7 @@ describe.concurrent.each([{ type: 'pg' } /** , { type: 'http' }*/])('Drizzle $ty
171
174
 
172
175
  afterEach(async (ctx) => {
173
176
  await ctx.client?.end();
174
- await api.branches.deleteBranch({ workspace, database, region, branch: ctx.branch });
177
+ await api.branch.deleteBranch({ pathParams: { workspace, region, dbBranchName: `${dbName}:${ctx.branch}` } });
175
178
  });
176
179
 
177
180
  /*
@@ -891,133 +894,6 @@ describe.concurrent.each([{ type: 'pg' } /** , { type: 'http' }*/])('Drizzle $ty
891
894
  });
892
895
  });
893
896
 
894
- test('[Find Many] Get users with posts in transaction', async (ctx) => {
895
- let usersWithPosts: {
896
- id: number;
897
- name: string;
898
- verified: boolean;
899
- invitedBy: number | null;
900
- posts: {
901
- id: number;
902
- content: string;
903
- ownerId: number | null;
904
- createdAt: Date;
905
- }[];
906
- }[] = [];
907
-
908
- await ctx.db.transaction(async (tx) => {
909
- await tx.insert(usersTable).values([
910
- { id: 1, name: 'Dan' },
911
- { id: 2, name: 'Andrew' },
912
- { id: 3, name: 'Alex' }
913
- ]);
914
-
915
- await tx.insert(postsTable).values([
916
- { ownerId: 1, content: 'Post1' },
917
- { ownerId: 1, content: 'Post1.1' },
918
- { ownerId: 2, content: 'Post2' },
919
- { ownerId: 3, content: 'Post3' }
920
- ]);
921
-
922
- usersWithPosts = await tx.query.usersTable.findMany({
923
- where: ({ id }, { eq }) => eq(id, 1),
924
- with: {
925
- posts: {
926
- where: ({ id }, { eq }) => eq(id, 1)
927
- }
928
- }
929
- });
930
- });
931
-
932
- expectTypeOf(usersWithPosts).toEqualTypeOf<
933
- {
934
- id: number;
935
- name: string;
936
- verified: boolean;
937
- invitedBy: number | null;
938
- posts: {
939
- id: number;
940
- content: string;
941
- ownerId: number | null;
942
- createdAt: Date;
943
- }[];
944
- }[]
945
- >();
946
-
947
- ctx.expect(usersWithPosts.length).eq(1);
948
- ctx.expect(usersWithPosts[0]?.posts.length).eq(1);
949
-
950
- ctx.expect(usersWithPosts[0]).toEqual({
951
- id: 1,
952
- name: 'Dan',
953
- verified: false,
954
- invitedBy: null,
955
- posts: [{ id: 1, ownerId: 1, content: 'Post1', createdAt: usersWithPosts[0]?.posts[0]?.createdAt }]
956
- });
957
- });
958
-
959
- test('[Find Many] Get users with posts in rollbacked transaction', async (ctx) => {
960
- let usersWithPosts: {
961
- id: number;
962
- name: string;
963
- verified: boolean;
964
- invitedBy: number | null;
965
- posts: {
966
- id: number;
967
- content: string;
968
- ownerId: number | null;
969
- createdAt: Date;
970
- }[];
971
- }[] = [];
972
-
973
- await ctx
974
- .expect(
975
- ctx.db.transaction(async (tx) => {
976
- await tx.insert(usersTable).values([
977
- { id: 1, name: 'Dan' },
978
- { id: 2, name: 'Andrew' },
979
- { id: 3, name: 'Alex' }
980
- ]);
981
-
982
- await tx.insert(postsTable).values([
983
- { ownerId: 1, content: 'Post1' },
984
- { ownerId: 1, content: 'Post1.1' },
985
- { ownerId: 2, content: 'Post2' },
986
- { ownerId: 3, content: 'Post3' }
987
- ]);
988
-
989
- tx.rollback();
990
-
991
- usersWithPosts = await tx.query.usersTable.findMany({
992
- where: ({ id }, { eq }) => eq(id, 1),
993
- with: {
994
- posts: {
995
- where: ({ id }, { eq }) => eq(id, 1)
996
- }
997
- }
998
- });
999
- })
1000
- )
1001
- .rejects.toThrowError(new TransactionRollbackError());
1002
-
1003
- expectTypeOf(usersWithPosts).toEqualTypeOf<
1004
- {
1005
- id: number;
1006
- name: string;
1007
- verified: boolean;
1008
- invitedBy: number | null;
1009
- posts: {
1010
- id: number;
1011
- content: string;
1012
- ownerId: number | null;
1013
- createdAt: Date;
1014
- }[];
1015
- }[]
1016
- >();
1017
-
1018
- ctx.expect(usersWithPosts.length).eq(0);
1019
- });
1020
-
1021
897
  // select only custom
1022
898
  test('[Find Many] Get only custom fields', async (ctx) => {
1023
899
  await ctx.db.insert(usersTable).values([
@@ -6409,12 +6285,12 @@ describe.concurrent.each([{ type: 'pg' } /** , { type: 'http' }*/])('Drizzle $ty
6409
6285
  });
6410
6286
  });
6411
6287
 
6412
- async function waitForReplication(): Promise<void> {
6288
+ async function waitForReplication(dbName: string): Promise<void> {
6413
6289
  try {
6414
6290
  await new Promise((resolve) => setTimeout(resolve, 2000));
6415
- await api.branches.getBranchList({ workspace, database, region });
6291
+ await api.branch.getBranchList({ pathParams: { workspace, dbName, region } });
6416
6292
  } catch (error) {
6417
6293
  console.log(`Replication not ready yet, retrying...`);
6418
- return await waitForReplication();
6294
+ return await waitForReplication(dbName);
6419
6295
  }
6420
6296
  }