CARVIEW |
Select Language
HTTP/2 200
date: Sun, 20 Jul 2025 02:41:52 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
x-repository-download: git clone https://github.com/neo4j/neo4j-javascript-driver.git
etag: W/"2437cb804f7261786ea6ce0932171e8b"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=6yu0%2Bb87C3Lpr8MZB4M7w64WNWxu0zZTbizRGtY1rf9H52u5U9i1SEU7V4ngYrTBmAyZeUvjRvveBrK4XMPTa7kcNefiR7pTPK6A5zKXwMb0Mq%2BH9Dm%2Flq2349tlshkxTjac55vj495XET0jIlZkmWcbK8hsV74p8SktK%2F%2BhviHnyDZFPRfkLo%2FmGz%2BHRB3MJJqckedEO%2BIgIjVpZ2vtocD%2Fs3HAspqXW2AE5PbR2Sm5R0b7MWws52m0e%2FriW%2FqsGxgXBwLh6pDlS6T%2B%2FFpMtA%3D%3D--K5zkuYa8cuhmLzBG--hc18ZOjMdHGh0YNH9Xm42A%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.2046667758.1752979311; Path=/; Domain=github.com; Expires=Mon, 20 Jul 2026 02:41:51 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Mon, 20 Jul 2026 02:41:51 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: A354:AA839:98EA49:C6C227:687C576F
Add generics and type mapping to Result, Session.run and Transaction.… · neo4j/neo4j-javascript-driver@6105c26 · GitHub
⚠️ This type definitions are not asserted in runtime. Thus mismatched type records coming from the database will not trigger type errors.
Copy file name to clipboardExpand all lines: packages/core/src/record.ts
Copy file name to clipboardExpand all lines: packages/core/src/result.ts
Copy file name to clipboardExpand all lines: packages/core/src/session.ts
Copy file name to clipboardExpand all lines: packages/core/src/transaction-managed.ts
Copy file name to clipboardExpand all lines: packages/core/src/transaction.ts
Copy file name to clipboardExpand all lines: packages/core/test/result.test.ts
Copy file name to clipboardExpand all lines: packages/neo4j-driver-deno/lib/core/record.ts
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit 6105c26
authored
Add generics and type mapping to Result, Session.run and Transaction.run (#1010)
The new generic typing allow mapping the records of these running queries to type-mapped Record.
Given the following Person and Friendship definitions.
```typescript
interface Person {
age: Integer
name: string
}
interface Friendship {
since: Integer
}
interface PersonAndFriendship {
p: Node<number, Person>
f: Relationship<number, Friendship>
}
```
The new type-mapping allow safe access the properties of query which return `Record<Person>`
```typescript
const { records } = await session.run<Person>('MATCH (p:Person) RETURN p.name as name, p.age as age')
for (const person of records) {
const age: Integer = person.get('age')
const name: string = person.get('name')
// @ts-expect-error
const nameInt: Integer = person.get('name')
}
```
The type-mapping can be also extended for `Node` and `Relationship`.
```typescript
const { records } = await session.run<PersonAndFriendship>('MATCH (p:Person)-[f:Friendship]-() RETURN p, f')
for (const r of records) {
const person = r.get('p')
const age: Integer = person.properties.age
const name: string = person.properties.name
// @ts-expect-error
const nameInt: Integer = person.properties.name
// @ts-expect-error
const err: string = person.properties.err
const friendship = r.get('f')
const since: Integer = friendship.properties.since
// @ts-expect-error
const sinceString: string = friendship.properties.since
// @ts-expect-error
const err2: string = friendship.properties.err
}
```
The usage in combination with `executeRead` and `executeWrite` is also possible.
```typescript
const { records } = await session.executeRead(tx => tx.run<Person>('MATCH (p:Person) RETURN p.name as name, p.age as age'))
for (const person of records) {
const age: Integer = person.get('age')
const name: string = person.get('name')
// @ts-expect-error
const nameInt: Integer = person.get('name')
}
```
With some async iterator usage:
```typescript
const personList = await session.executeRead(async (tx) => {
const result = tx.run<Person>('MATCH (p:Person) RETURN p.name as name, p.age as age')
const objects: Person[] = []
// iterate while streaming the objects
for await (const record of result) {
objects.push(record.toObject())
}
return objects
})
for (const person of personList) {
const age: Integer = person.age
const name: string = person.name
// @ts-expect-error
const nameInt: Integer = person.name
// @ts-expect-error
const nome: string = person.nome
}
```
1 parent b1ff30b commit 6105c26Copy full SHA for 6105c26
File tree
Expand file treeCollapse file tree
14 files changed
+307
-40
lines changedFilter options
- packages
- core
- src
- test
- neo4j-driver-deno/lib/core
- neo4j-driver/test/types
Expand file treeCollapse file tree
14 files changed
+307
-40
lines changedpackages/core/src/record.ts
Copy file name to clipboardExpand all lines: packages/core/src/record.ts+1Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
243 | 243 |
| |
244 | 244 |
| |
245 | 245 |
| |
| 246 | + |
packages/core/src/result.ts
Copy file name to clipboardExpand all lines: packages/core/src/result.ts+14-14Lines changed: 14 additions & 14 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
20 | 20 |
| |
21 | 21 |
| |
22 | 22 |
| |
23 |
| - | |
| 23 | + | |
24 | 24 |
| |
25 | 25 |
| |
26 | 26 |
| |
| |||
56 | 56 |
| |
57 | 57 |
| |
58 | 58 |
| |
59 |
| - | |
60 |
| - | |
| 59 | + | |
| 60 | + | |
61 | 61 |
| |
62 | 62 |
| |
63 | 63 |
| |
64 | 64 |
| |
65 | 65 |
| |
66 | 66 |
| |
67 | 67 |
| |
68 |
| - | |
| 68 | + | |
69 | 69 |
| |
70 | 70 |
| |
71 | 71 |
| |
| |||
77 | 77 |
| |
78 | 78 |
| |
79 | 79 |
| |
80 |
| - | |
| 80 | + | |
81 | 81 |
| |
82 | 82 |
| |
83 | 83 |
| |
| |||
111 | 111 |
| |
112 | 112 |
| |
113 | 113 |
| |
114 |
| - | |
| 114 | + | |
115 | 115 |
| |
116 | 116 |
| |
117 | 117 |
| |
| |||
212 | 212 |
| |
213 | 213 |
| |
214 | 214 |
| |
215 |
| - | |
| 215 | + | |
216 | 216 |
| |
217 | 217 |
| |
218 | 218 |
| |
| |||
240 | 240 |
| |
241 | 241 |
| |
242 | 242 |
| |
243 |
| - | |
| 243 | + | |
244 | 244 |
| |
245 |
| - | |
| 245 | + | |
246 | 246 |
| |
247 | 247 |
| |
248 | 248 |
| |
| |||
345 | 345 |
| |
346 | 346 |
| |
347 | 347 |
| |
348 |
| - | |
| 348 | + | |
349 | 349 |
| |
350 |
| - | |
| 350 | + | |
351 | 351 |
| |
352 | 352 |
| |
353 | 353 |
| |
| |||
364 | 364 |
| |
365 | 365 |
| |
366 | 366 |
| |
367 |
| - | |
| 367 | + | |
368 | 368 |
| |
369 | 369 |
| |
370 | 370 |
| |
| |||
376 | 376 |
| |
377 | 377 |
| |
378 | 378 |
| |
379 |
| - | |
| 379 | + | |
380 | 380 |
| |
381 | 381 |
| |
382 | 382 |
| |
| |||
391 | 391 |
| |
392 | 392 |
| |
393 | 393 |
| |
394 |
| - | |
| 394 | + | |
395 | 395 |
| |
396 | 396 |
| |
397 | 397 |
| |
|
packages/core/src/session.ts
Copy file name to clipboardExpand all lines: packages/core/src/session.ts+3-2Lines changed: 3 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
36 | 36 |
| |
37 | 37 |
| |
38 | 38 |
| |
| 39 | + | |
39 | 40 |
| |
40 | 41 |
| |
41 | 42 |
| |
| |||
154 | 155 |
| |
155 | 156 |
| |
156 | 157 |
| |
157 |
| - | |
| 158 | + | |
158 | 159 |
| |
159 | 160 |
| |
160 | 161 |
| |
161 |
| - | |
| 162 | + | |
162 | 163 |
| |
163 | 164 |
| |
164 | 165 |
| |
|
packages/core/src/transaction-managed.ts
Copy file name to clipboardExpand all lines: packages/core/src/transaction-managed.ts+2-1Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
20 | 20 |
| |
21 | 21 |
| |
22 | 22 |
| |
| 23 | + | |
23 | 24 |
| |
24 | 25 |
| |
25 | 26 |
| |
| |||
60 | 61 |
| |
61 | 62 |
| |
62 | 63 |
| |
63 |
| - | |
| 64 | + | |
64 | 65 |
| |
65 | 66 |
| |
66 | 67 |
| |
|
packages/core/src/transaction.ts
Copy file name to clipboardExpand all lines: packages/core/src/transaction.ts+3-2Lines changed: 3 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
37 | 37 |
| |
38 | 38 |
| |
39 | 39 |
| |
| 40 | + | |
40 | 41 |
| |
41 | 42 |
| |
42 | 43 |
| |
| |||
109 | 110 |
| |
110 | 111 |
| |
111 | 112 |
| |
112 |
| - | |
| 113 | + | |
113 | 114 |
| |
114 | 115 |
| |
115 | 116 |
| |
| |||
174 | 175 |
| |
175 | 176 |
| |
176 | 177 |
| |
177 |
| - | |
| 178 | + | |
178 | 179 |
| |
179 | 180 |
| |
180 | 181 |
| |
|
packages/core/test/result.test.ts
Copy file name to clipboardExpand all lines: packages/core/test/result.test.ts+100Lines changed: 100 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
28 | 28 |
| |
29 | 29 |
| |
30 | 30 |
| |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
31 | 36 |
| |
32 | 37 |
| |
33 | 38 |
| |
| |||
305 | 310 |
| |
306 | 311 |
| |
307 | 312 |
| |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
308 | 341 |
| |
309 | 342 |
| |
310 | 343 |
| |
| |||
540 | 573 |
| |
541 | 574 |
| |
542 | 575 |
| |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
543 | 615 |
| |
544 | 616 |
| |
545 | 617 |
| |
| |||
808 | 880 |
| |
809 | 881 |
| |
810 | 882 |
| |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
811 | 911 |
| |
812 | 912 |
| |
813 | 913 |
| |
|
packages/neo4j-driver-deno/lib/core/record.ts
Copy file name to clipboardExpand all lines: packages/neo4j-driver-deno/lib/core/record.ts+1Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
243 | 243 |
| |
244 | 244 |
| |
245 | 245 |
| |
| 246 | + |
You can’t perform that action at this time.
0 commit comments