-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
31 lines (26 loc) · 886 Bytes
/
main.ts
File metadata and controls
31 lines (26 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { createClient } from './db';
async function main() {
const db = await createClient();
try {
await db.user.create({
// @ts-expect-error missing required 'age' field
data: { email: 'u1@test.com', profile: { gender: 'male' } }
});
} catch (err: any) {
console.log('Got expected error:', err.message);
}
// query results have the `profile` field strongly typed
const user = await db.user.create({
data: { email: 'u1@test.com', profile: { gender: 'male', age: 20 } }
});
console.log(`User created: age ${user.profile.age}, gender ${user.profile.gender}`);
// it doesn't prevent you from adding extra fields to the object
console.log('Update typed-JSON field with extra fields');
console.log(
await db.user.update({
where: { id: user.id },
data: { profile: { ...user.profile, tag: 'vip' } }
})
);
}
main();