Skip to content

Commit 07a800c

Browse files
committed
addressing PR comments
1 parent 31606b8 commit 07a800c

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

packages/language/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ export function getAllDeclarationsIncludingImports(documents: LangiumDocuments,
445445
export function getAuthDecl(decls: (DataModel | TypeDef)[]) {
446446
let authModel = decls.find((d) => hasAttribute(d, '@@auth'));
447447
if (!authModel) {
448-
authModel = decls.find((d) => (isDataModel(d) || isTypeDef(d)) && d.name === 'User');
448+
authModel = decls.find((d) => d.name === 'User');
449449
}
450450
return authModel;
451451
}

packages/runtime/src/client/client-impl.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,9 @@ export class ClientImpl<Schema extends SchemaDef> {
234234
}
235235

236236
async $connect() {
237-
await this.kysely.connection().execute(async () => {});
237+
await this.kysely.connection().execute(async (conn) => {
238+
await conn.executeQuery(sql`select 1`.compile(this.kysely));
239+
});
238240
}
239241

240242
async $disconnect() {

packages/runtime/src/client/executor/zenstack-query-executor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class ZenStackQueryExecutor<Schema extends SchemaDef> extends DefaultQuer
6060
}
6161
}
6262

63-
private schemaHasMappedNames<Schema extends SchemaDef>(schema: Schema) {
63+
private schemaHasMappedNames(schema: Schema) {
6464
const hasMapAttr = (decl: ModelDef | TypeDefDef) => {
6565
if (decl.attributes?.some((attr) => attr.name === '@@map')) {
6666
return true;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { createTestClient } from '@zenstackhq/testtools';
2+
import { describe, expect, it } from 'vitest';
3+
4+
describe('Client $connect and $disconnect tests', () => {
5+
it('works with connect and disconnect', async () => {
6+
const db = await createTestClient(
7+
`
8+
model User {
9+
id String @id @default(cuid())
10+
email String @unique
11+
}
12+
`,
13+
);
14+
15+
// connect to the database
16+
await db.$connect();
17+
18+
// perform a simple operation
19+
await db.user.create({
20+
data: {
21+
22+
},
23+
});
24+
25+
await db.$disconnect();
26+
27+
await expect(db.user.findFirst()).rejects.toThrow();
28+
});
29+
});

0 commit comments

Comments
 (0)