diff --git a/docs/index.html b/docs/index.html index 7f21488..9d37d8a 100644 --- a/docs/index.html +++ b/docs/index.html @@ -280,7 +280,7 @@
A general configuration suggestion: set up ESLint with the rules @typescript-eslint/await-thenable
and @typescript-eslint/no-floating-promises
(or the now-deprecated tslint with no-floating-promises
and await-promise
) to avoid various Promise
-related pitfalls.
A general configuration suggestion: set up ESLint with the rules @typescript-eslint/await-thenable
and @typescript-eslint/no-floating-promises
(or the now-deprecated tslint with no-floating-promises
and await-promise
) to avoid various Promise
-related pitfalls.
Zapatos provides a command line tool. With everything configured, run it like so:
npx zapatos
@@ -680,10 +680,10 @@ sql
tagged template stringsSELECT random()
[
{
- "random": 0.4620805530200762
+ "random": 0.621588923150834
}
]
-0.4620805530200762
+0.621588923150834
Interpolations
is never
because nothing needs to be interpolated in this query, and the RunResult
type says that the query will return one row comprising one numeric column, named random
. The random
TypeScript variable we initialize will of course be typed as a number
.
If you’re happy to have your types tied down a little less tightly, it also works to wholly omit the type variables in this particular query, falling back on their defaults:
@@ -823,7 +823,7 @@Whereable
Whereable
Whereable
runResultTransform: (qr:
const dbNow = await dbNowQuery().run(pool);
// dbNow is a Date: the result you can toggle below has come via JSON.stringify
SELECT now()
-"2024-01-08T11:51:14.463Z"
+"2024-06-23T14:24:09.784Z"
Note that the RunResult
type variable on the sql
template function (in this case, Date
) must reflect the type of the transformed result, not what comes straight back from pg
(which in this case is roughly { rows: [{ now: Date }] }
).
If a SQLFragment
does not have run
called on it directly — for example, if it is instead interpolated into another SQLFragment
, or given as the value of the lateral
option to the select
shortcut — then the runResultTransform
function is never applied.
insert
INSERT INTO "tags" ("bookId", "tag")
@@ -1415,7 +1415,7 @@ update
[
{
"email": "me@privacy.net",
- "lastFailedLogin": "2024-01-08T11:51:16.550739+00:00",
+ "lastFailedLogin": "2024-06-23T15:24:11.210042+01:00",
"consecutiveFailedLogins": 1
}
]
@@ -1521,7 +1521,7 @@ upsert
options
The updateColumns
option allows us to specify a subset of columns (as either one name or an array of names) that are to be updated on conflict. For example, you might want to include all columns except createdAt
in this list.
-The noNullUpdateColumns
option takes a column name or array of column names which are not to be overwritten with NULL
in the case that the UPDATE
branch is taken.
+The noNullUpdateColumns
option takes a column name or array of column names which are not to be overwritten with NULL
in the case that the UPDATE
branch is taken. It can also take the special value db.all
to indicate that no column should ever be overwritten with NULL
.
The updateValues
option allows us to specify alternative column values to be used in the UPDATE
query branch: see below.
@@ -1563,7 +1563,7 @@ INSERT ... ON CONFLICT ... DO NOT
{
"code": "XYE953ZVU767",
"$action": "INSERT",
- "redeemedAt": "2024-01-08T11:51:17.298226+00:00"
+ "redeemedAt": "2024-06-23T15:24:11.733317+01:00"
}
INSERT INTO "usedVoucherCodes" ("code")
VALUES ($1)
@@ -1697,43 +1697,43 @@ select
, select
"id": 1000,
"title": "Northern Lights",
"authorId": 1000,
- "createdAt": "2024-01-08T11:50:21.508324+00:00"
+ "createdAt": "2024-06-23T15:22:52.603082+01:00"
},
{
"id": 1001,
"title": "The Subtle Knife",
"authorId": 1000,
- "createdAt": "2024-01-08T11:50:21.50977+00:00"
+ "createdAt": "2024-06-23T15:22:52.603558+01:00"
},
{
"id": 1002,
"title": "The Amber Spyglass",
"authorId": 1000,
- "createdAt": "2024-01-08T11:50:21.510292+00:00"
+ "createdAt": "2024-06-23T15:22:52.603732+01:00"
},
{
"id": 1003,
"title": "The Curious Incident of the Dog in the Night-Time",
"authorId": 1001,
- "createdAt": "2024-01-08T11:50:21.513693+00:00"
+ "createdAt": "2024-06-23T15:22:52.605245+01:00"
},
{
"id": 1,
"title": "A Brief History of Time",
"authorId": 5,
- "createdAt": "2024-01-08T11:51:15.452677+00:00"
+ "createdAt": "2024-06-23T15:24:10.463945+01:00"
},
{
"id": 2,
"title": "My Brief History",
"authorId": 5,
- "createdAt": "2024-01-08T11:51:15.452677+00:00"
+ "createdAt": "2024-06-23T15:24:10.463945+01:00"
},
{
"id": 3,
"title": "The Universe in a Nutshell",
"authorId": 5,
- "createdAt": "2024-01-08T11:51:15.457539+00:00"
+ "createdAt": "2024-06-23T15:24:10.467708+01:00"
}
]
@@ -1751,19 +1751,19 @@ select
, select
"id": 1000,
"title": "Northern Lights",
"authorId": 1000,
- "createdAt": "2024-01-08T11:50:21.508324+00:00"
+ "createdAt": "2024-06-23T15:22:52.603082+01:00"
},
{
"id": 1001,
"title": "The Subtle Knife",
"authorId": 1000,
- "createdAt": "2024-01-08T11:50:21.50977+00:00"
+ "createdAt": "2024-06-23T15:22:52.603558+01:00"
},
{
"id": 1002,
"title": "The Amber Spyglass",
"authorId": 1000,
- "createdAt": "2024-01-08T11:50:21.510292+00:00"
+ "createdAt": "2024-06-23T15:22:52.603732+01:00"
}
]
@@ -1817,7 +1817,7 @@ select
, select
"id": 1003,
"title": "The Curious Incident of the Dog in the Night-Time",
"authorId": 1001,
- "createdAt": "2024-01-08T11:50:21.513693+00:00"
+ "createdAt": "2024-06-23T15:22:52.605245+01:00"
}
]
@@ -1840,7 +1840,7 @@ select
, select
"id": 1003,
"title": "The Curious Incident of the Dog in the Night-Time",
"authorId": 1001,
- "createdAt": "2024-01-08T11:50:21.513693+00:00"
+ "createdAt": "2024-06-23T15:22:52.605245+01:00"
}
]
@@ -1862,7 +1862,7 @@ select
, select
"id": 1,
"title": "A Brief History of Time",
"authorId": 5,
- "createdAt": "2024-01-08T11:51:15.452677+00:00"
+ "createdAt": "2024-06-23T15:24:10.463945+01:00"
}
]
@@ -1930,7 +1930,7 @@ order
, limit
and "id": 1,
"title": "A Brief History of Time",
"authorId": 5,
- "createdAt": "2024-01-08T11:51:15.452677+00:00"
+ "createdAt": "2024-06-23T15:24:10.463945+01:00"
}
]
@@ -1950,7 +1950,7 @@ order
, limit
and "id": 1,
"title": "A Brief History of Time",
"authorId": 5,
- "createdAt": "2024-01-08T11:51:15.452677+00:00"
+ "createdAt": "2024-06-23T15:24:10.463945+01:00"
}
The { limit: 1 }
option is now applied automatically. And the return type following await
needs no destructuring and is now, correctly, JSONSelectable | undefined
.
lateral
property mapslateral
property mapslateral
property mapslateral
property mapslateral
property mapslateral
property mapslateral
property mapslateral
property mapslateral
property mapslateral
property mapslateral
property mapslateral
property mapslateral
property mapsextras
extras
extras
extras
extras
distinct
[
{
+ "id": 2,
+ "title": "My Brief History",
+ "authorId": 5,
+ "createdAt": "2024-06-23T15:24:10.463945+01:00"
+ },
+ {
"id": 1002,
"title": "The Amber Spyglass",
"authorId": 1000,
- "createdAt": "2024-01-08T11:50:21.510292+00:00"
+ "createdAt": "2024-06-23T15:22:52.603732+01:00"
},
{
- "id": 1001,
- "title": "The Subtle Knife",
+ "id": 1000,
+ "title": "Northern Lights",
"authorId": 1000,
- "createdAt": "2024-01-08T11:50:21.50977+00:00"
+ "createdAt": "2024-06-23T15:22:52.603082+01:00"
},
{
"id": 1003,
"title": "The Curious Incident of the Dog in the Night-Time",
"authorId": 1001,
- "createdAt": "2024-01-08T11:50:21.513693+00:00"
+ "createdAt": "2024-06-23T15:22:52.605245+01:00"
},
{
- "id": 2,
- "title": "My Brief History",
+ "id": 1,
+ "title": "A Brief History of Time",
"authorId": 5,
- "createdAt": "2024-01-08T11:51:15.452677+00:00"
+ "createdAt": "2024-06-23T15:24:10.463945+01:00"
},
{
- "id": 1000,
- "title": "Northern Lights",
+ "id": 1001,
+ "title": "The Subtle Knife",
"authorId": 1000,
- "createdAt": "2024-01-08T11:50:21.508324+00:00"
- },
- {
- "id": 1,
- "title": "A Brief History of Time",
- "authorId": 5,
- "createdAt": "2024-01-08T11:51:15.452677+00:00"
+ "createdAt": "2024-06-23T15:22:52.603558+01:00"
},
{
"id": 3,
"title": "The Universe in a Nutshell",
"authorId": 5,
- "createdAt": "2024-01-08T11:51:15.457539+00:00"
+ "createdAt": "2024-06-23T15:24:10.467708+01:00"
}
]
SELECT coalesce(jsonb_agg(result), '[]') AS result
@@ -2803,43 +2833,43 @@ distinct
"id": 1,
"title": "A Brief History of Time",
"authorId": 5,
- "createdAt": "2024-01-08T11:51:15.452677+00:00"
+ "createdAt": "2024-06-23T15:24:10.463945+01:00"
},
{
"id": 2,
"title": "My Brief History",
"authorId": 5,
- "createdAt": "2024-01-08T11:51:15.452677+00:00"
+ "createdAt": "2024-06-23T15:24:10.463945+01:00"
},
{
"id": 1000,
"title": "Northern Lights",
"authorId": 1000,
- "createdAt": "2024-01-08T11:50:21.508324+00:00"
+ "createdAt": "2024-06-23T15:22:52.603082+01:00"
},
{
"id": 1002,
"title": "The Amber Spyglass",
"authorId": 1000,
- "createdAt": "2024-01-08T11:50:21.510292+00:00"
+ "createdAt": "2024-06-23T15:22:52.603732+01:00"
},
{
"id": 1003,
"title": "The Curious Incident of the Dog in the Night-Time",
"authorId": 1001,
- "createdAt": "2024-01-08T11:50:21.513693+00:00"
+ "createdAt": "2024-06-23T15:22:52.605245+01:00"
},
{
"id": 1001,
"title": "The Subtle Knife",
"authorId": 1000,
- "createdAt": "2024-01-08T11:50:21.50977+00:00"
+ "createdAt": "2024-06-23T15:22:52.603558+01:00"
},
{
"id": 3,
"title": "The Universe in a Nutshell",
"authorId": 5,
- "createdAt": "2024-01-08T11:51:15.457539+00:00"
+ "createdAt": "2024-06-23T15:24:10.467708+01:00"
}
]
SELECT coalesce(jsonb_agg(result), '[]') AS result
@@ -2851,43 +2881,43 @@ distinct
"id": 1,
"title": "A Brief History of Time",
"authorId": 5,
- "createdAt": "2024-01-08T11:51:15.452677+00:00"
+ "createdAt": "2024-06-23T15:24:10.463945+01:00"
},
{
"id": 2,
"title": "My Brief History",
"authorId": 5,
- "createdAt": "2024-01-08T11:51:15.452677+00:00"
+ "createdAt": "2024-06-23T15:24:10.463945+01:00"
},
{
"id": 1000,
"title": "Northern Lights",
"authorId": 1000,
- "createdAt": "2024-01-08T11:50:21.508324+00:00"
+ "createdAt": "2024-06-23T15:22:52.603082+01:00"
},
{
"id": 1002,
"title": "The Amber Spyglass",
"authorId": 1000,
- "createdAt": "2024-01-08T11:50:21.510292+00:00"
+ "createdAt": "2024-06-23T15:22:52.603732+01:00"
},
{
"id": 1003,
"title": "The Curious Incident of the Dog in the Night-Time",
"authorId": 1001,
- "createdAt": "2024-01-08T11:50:21.513693+00:00"
+ "createdAt": "2024-06-23T15:22:52.605245+01:00"
},
{
"id": 1001,
"title": "The Subtle Knife",
"authorId": 1000,
- "createdAt": "2024-01-08T11:50:21.50977+00:00"
+ "createdAt": "2024-06-23T15:22:52.603558+01:00"
},
{
"id": 3,
"title": "The Universe in a Nutshell",
"authorId": 5,
- "createdAt": "2024-01-08T11:51:15.457539+00:00"
+ "createdAt": "2024-06-23T15:24:10.467708+01:00"
}
]
SELECT coalesce(jsonb_agg(result), '[]') AS result
@@ -2899,43 +2929,43 @@ distinct
"id": 1,
"title": "A Brief History of Time",
"authorId": 5,
- "createdAt": "2024-01-08T11:51:15.452677+00:00"
+ "createdAt": "2024-06-23T15:24:10.463945+01:00"
},
{
"id": 2,
"title": "My Brief History",
"authorId": 5,
- "createdAt": "2024-01-08T11:51:15.452677+00:00"
+ "createdAt": "2024-06-23T15:24:10.463945+01:00"
},
{
"id": 1000,
"title": "Northern Lights",
"authorId": 1000,
- "createdAt": "2024-01-08T11:50:21.508324+00:00"
+ "createdAt": "2024-06-23T15:22:52.603082+01:00"
},
{
"id": 1002,
"title": "The Amber Spyglass",
"authorId": 1000,
- "createdAt": "2024-01-08T11:50:21.510292+00:00"
+ "createdAt": "2024-06-23T15:22:52.603732+01:00"
},
{
"id": 1003,
"title": "The Curious Incident of the Dog in the Night-Time",
"authorId": 1001,
- "createdAt": "2024-01-08T11:50:21.513693+00:00"
+ "createdAt": "2024-06-23T15:22:52.605245+01:00"
},
{
"id": 1001,
"title": "The Subtle Knife",
"authorId": 1000,
- "createdAt": "2024-01-08T11:50:21.50977+00:00"
+ "createdAt": "2024-06-23T15:22:52.603558+01:00"
},
{
"id": 3,
"title": "The Universe in a Nutshell",
"authorId": 5,
- "createdAt": "2024-01-08T11:51:15.457539+00:00"
+ "createdAt": "2024-06-23T15:24:10.467708+01:00"
}
]
@@ -3088,13 +3118,13 @@ JSONSelectable
transaction
["2020-12-25", 2]
-Transaction 0
+Transaction 1
[
{
"day": "2020-12-25",
- "doctorId": 1
+ "doctorId": 2
}
]
-Transaction 0
-COMMIT
Transaction 1
+COMMIT
+Transaction 0
[
{
"day": "2020-12-25",
- "doctorId": 2
+ "doctorId": 1
}
]
-Transaction 1
+Transaction 0
COMMIT
-Transaction 1
+Transaction 0
ROLLBACK
-Transaction 1
-Transaction rollback (code 40001) on attempt 1 of 5, retrying in 151ms
-Transaction 1
+Transaction 0
+Transaction rollback (code 40001) on attempt 1 of 5, retrying in 98ms
+Transaction 0
Retrying transaction, attempt 2 of 5
-Transaction 1
+Transaction 0
START TRANSACTION ISOLATION LEVEL SERIALIZABLE
-Transaction 1
+Transaction 0
SELECT count("shifts".*) AS result
FROM "shifts"
WHERE ("day" = $1
AND ("doctorId" != $2))
-["2020-12-25", 2]
-Transaction 1
+["2020-12-25", 1]
+Transaction 0
0
-Transaction 1
+Transaction 0
COMMIT
Leave booked for:
- Annabel – true
- Brian – false
+ Annabel – false
+ Brian – true
Expanding the results, we see that one of the requests is retried and then fails — as it must to retain one doctor on shift — thanks to the SERIALIZABLE
isolation. REPEATABLE READ
, which is one isolation level weaker, wouldn’t help here.