Skip to content

Commit bc81a7f

Browse files
committed
Rename 'map' method to 'reify', anticipating a future flag
1 parent c301949 commit bc81a7f

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ In next release ...
77
- Query results are now generic with typing support for the `get`
88
method on each row.
99

10-
In addition, a new `map` method now produces records which conform
10+
In addition, a new `reify` method now produces records which conform
1111
to the specified type. This method is available on all of the result
1212
objects.
1313

src/result.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class ResultRowImpl<T> {
2929
return this.data[i];
3030
}
3131

32-
map(): T {
32+
reify(): T {
3333
const data = this.data;
3434
const result: Record<string, any> = {};
3535
this.names.forEach((key, i) => result[key] = data[i]);
@@ -71,7 +71,7 @@ export class Result<T = ResultRecord> {
7171
}
7272
}
7373

74-
map(): T[] {
74+
reify(): T[] {
7575
return this.rows.map(data => {
7676
const result: Record<string, any> = {};
7777
this.names.forEach((key, i) => result[key] = data[i]);
@@ -116,15 +116,15 @@ export class ResultIterator<T = ResultRecord> extends Promise<Result<T>> {
116116
throw new Error('Query returned an empty result');
117117
}
118118

119-
map(): AsyncIterable<T> {
119+
reify(): AsyncIterable<T> {
120120
const iterator: AsyncIterator<ResultRow<T>> = this[Symbol.asyncIterator]();
121121
return {
122122
[Symbol.asyncIterator]() {
123123
return {
124124
async next() {
125125
const { done, value } = await iterator.next();
126126
if (done) return { done, value: null };
127-
return { done, value: value.map() };
127+
return { done, value: value.reify() };
128128
},
129129
async return() {
130130
if (iterator?.return) await iterator?.return();

test/result.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ describe('Result', () => {
6262
expect(result.status).toEqual('SELECT 1');
6363
expect(result.names.length).toEqual(1);
6464
expect(result.names[0]).toEqual('message');
65-
expect(result.map()).toEqual([{message: 'Hello world!'}]);
65+
expect(result.reify()).toEqual([{message: 'Hello world!'}]);
6666
const rows = [...result];
6767
const row = rows[0];
6868
expect(row.get('message')).toEqual('Hello world!');
6969
expect(row.get('bad')).toEqual(undefined);
70-
const mapped = row.map();
70+
const mapped = row.reify();
7171
expect(mapped.message).toEqual('Hello world!');
7272
});
7373

@@ -81,7 +81,7 @@ describe('Result', () => {
8181
const row = rows[0];
8282
const message: string = row.get('message');
8383
expect(message).toEqual('Hello world!');
84-
const mapped: {message: string} = row.map();
84+
const mapped: {message: string} = row.reify();
8585
expect(mapped.message).toEqual('Hello world!');
8686
});
8787

@@ -121,7 +121,7 @@ describe('Result', () => {
121121
expect.assertions(1);
122122
const mapped = client.query(
123123
'select $1::text as message', ['Hello world!']
124-
).map();
124+
).reify();
125125
for await (const item of mapped) {
126126
expect(item).toEqual({message: 'Hello world!'});
127127
}

0 commit comments

Comments
 (0)