@xata.io/drizzle 0.0.0-alpha.vbd744fbfa99b90b789b1bb5a5fd54aa692726df8 → 0.0.0-alpha.vbdff713273d365b4b3df439242ea62bddf05e9ec

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';
@@ -76,12 +76,11 @@ 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.concurrent.each([{ type: 'pg' }, { type: 'http' }])('Drizzle $type', ({ type }) => {
80
80
  beforeAll(async () => {
81
- await api.database.createDatabase({
82
- workspace,
83
- database,
84
- data: { region, branchName: 'main' },
81
+ await api.databases.createDatabase({
82
+ pathParams: { workspaceId: workspace, dbName: database },
83
+ body: { region, branchName: 'main' },
85
84
  headers: { 'X-Features': 'feat-pgroll-migrations=1' }
86
85
  });
87
86
 
@@ -155,12 +154,15 @@ describe.concurrent.each([{ type: 'pg' } /** , { type: 'http' }*/])('Drizzle $ty
155
154
  });
156
155
 
157
156
  afterAll(async () => {
158
- await api.database.deleteDatabase({ workspace, database });
157
+ await api.databases.deleteDatabase({ pathParams: { workspaceId: workspace, dbName: database } });
159
158
  });
160
159
 
161
160
  beforeEach(async (ctx) => {
162
161
  ctx.branch = `test-${Math.random().toString(36).substring(7)}`;
163
- await api.branches.createBranch({ workspace, database, region, branch: ctx.branch, from: 'main' });
162
+ await api.branch.createBranch({
163
+ pathParams: { workspace, region, dbBranchName: `${database}:${ctx.branch}` },
164
+ body: { from: 'main' }
165
+ });
164
166
 
165
167
  const { db, client } = getDrizzleClient(type, ctx.branch);
166
168
  await client?.connect();
@@ -171,7 +173,7 @@ describe.concurrent.each([{ type: 'pg' } /** , { type: 'http' }*/])('Drizzle $ty
171
173
 
172
174
  afterEach(async (ctx) => {
173
175
  await ctx.client?.end();
174
- await api.branches.deleteBranch({ workspace, database, region, branch: ctx.branch });
176
+ await api.branch.deleteBranch({ pathParams: { workspace, region, dbBranchName: `${database}:${ctx.branch}` } });
175
177
  });
176
178
 
177
179
  /*
@@ -891,133 +893,6 @@ describe.concurrent.each([{ type: 'pg' } /** , { type: 'http' }*/])('Drizzle $ty
891
893
  });
892
894
  });
893
895
 
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
896
  // select only custom
1022
897
  test('[Find Many] Get only custom fields', async (ctx) => {
1023
898
  await ctx.db.insert(usersTable).values([
@@ -6412,7 +6287,7 @@ describe.concurrent.each([{ type: 'pg' } /** , { type: 'http' }*/])('Drizzle $ty
6412
6287
  async function waitForReplication(): Promise<void> {
6413
6288
  try {
6414
6289
  await new Promise((resolve) => setTimeout(resolve, 2000));
6415
- await api.branches.getBranchList({ workspace, database, region });
6290
+ await api.branch.getBranchList({ pathParams: { workspace, dbName: database, region } });
6416
6291
  } catch (error) {
6417
6292
  console.log(`Replication not ready yet, retrying...`);
6418
6293
  return await waitForReplication();