@xata.io/drizzle 0.0.0-alpha.vbd744fbfa99b90b789b1bb5a5fd54aa692726df8 → 0.0.0-alpha.vbe89ca8d6fcdf0b668677503529491b009ed4d60
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/.turbo/turbo-build.log +16 -5
- package/CHANGELOG.md +29 -2
- package/dist/index.cjs +51 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +13 -9
- package/dist/index.mjs +52 -40
- package/dist/index.mjs.map +1 -1
- package/dist/pg.cjs +212 -0
- package/dist/pg.cjs.map +1 -0
- package/dist/pg.d.ts +61 -0
- package/dist/pg.mjs +206 -0
- package/dist/pg.mjs.map +1 -0
- package/package.json +11 -6
- package/test/drizzle.test.ts +2 -129
package/test/drizzle.test.ts
CHANGED
@@ -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
|
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,7 +76,7 @@ function getDrizzleClient(type: string, branch: string) {
|
|
76
76
|
}
|
77
77
|
}
|
78
78
|
|
79
|
-
describe.concurrent.each([{ type: 'pg' }
|
79
|
+
describe.concurrent.each([{ type: 'pg' }, { type: 'http' }])('Drizzle $type', ({ type }) => {
|
80
80
|
beforeAll(async () => {
|
81
81
|
await api.database.createDatabase({
|
82
82
|
workspace,
|
@@ -891,133 +891,6 @@ describe.concurrent.each([{ type: 'pg' } /** , { type: 'http' }*/])('Drizzle $ty
|
|
891
891
|
});
|
892
892
|
});
|
893
893
|
|
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
894
|
// select only custom
|
1022
895
|
test('[Find Many] Get only custom fields', async (ctx) => {
|
1023
896
|
await ctx.db.insert(usersTable).values([
|