diff --git a/docs/index.html b/docs/index.html index a0f7f59..7f21488 100644 --- a/docs/index.html +++ b/docs/index.html @@ -280,7 +280,7 @@
sql
tagged template stringsSELECT random()
[
{
- "random": 0.5511811017169812
+ "random": 0.4620805530200762
}
]
-0.5511811017169812
+0.4620805530200762
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()
-"2023-11-30T11:56:08.041Z"
+"2024-01-08T11:51:14.463Z"
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": "2023-11-30T11:56:10.736952+00:00",
+ "lastFailedLogin": "2024-01-08T11:51:16.550739+00:00",
"consecutiveFailedLogins": 1
}
]
@@ -1563,7 +1563,7 @@ INSERT ... ON CONFLICT ... DO NOT
{
"code": "XYE953ZVU767",
"$action": "INSERT",
- "redeemedAt": "2023-11-30T11:56:11.609362+00:00"
+ "redeemedAt": "2024-01-08T11:51:17.298226+00:00"
}
INSERT INTO "usedVoucherCodes" ("code")
VALUES ($1)
@@ -1697,43 +1697,43 @@ select
, select
"id": 1000,
"title": "Northern Lights",
"authorId": 1000,
- "createdAt": "2023-11-30T11:55:24.995182+00:00"
+ "createdAt": "2024-01-08T11:50:21.508324+00:00"
},
{
"id": 1001,
"title": "The Subtle Knife",
"authorId": 1000,
- "createdAt": "2023-11-30T11:55:24.996168+00:00"
+ "createdAt": "2024-01-08T11:50:21.50977+00:00"
},
{
"id": 1002,
"title": "The Amber Spyglass",
"authorId": 1000,
- "createdAt": "2023-11-30T11:55:24.996692+00:00"
+ "createdAt": "2024-01-08T11:50:21.510292+00:00"
},
{
"id": 1003,
"title": "The Curious Incident of the Dog in the Night-Time",
"authorId": 1001,
- "createdAt": "2023-11-30T11:55:25.000887+00:00"
+ "createdAt": "2024-01-08T11:50:21.513693+00:00"
},
{
"id": 1,
"title": "A Brief History of Time",
"authorId": 5,
- "createdAt": "2023-11-30T11:56:09.395795+00:00"
+ "createdAt": "2024-01-08T11:51:15.452677+00:00"
},
{
"id": 2,
"title": "My Brief History",
"authorId": 5,
- "createdAt": "2023-11-30T11:56:09.395795+00:00"
+ "createdAt": "2024-01-08T11:51:15.452677+00:00"
},
{
"id": 3,
"title": "The Universe in a Nutshell",
"authorId": 5,
- "createdAt": "2023-11-30T11:56:09.400222+00:00"
+ "createdAt": "2024-01-08T11:51:15.457539+00:00"
}
]
@@ -1751,19 +1751,19 @@ select
, select
"id": 1000,
"title": "Northern Lights",
"authorId": 1000,
- "createdAt": "2023-11-30T11:55:24.995182+00:00"
+ "createdAt": "2024-01-08T11:50:21.508324+00:00"
},
{
"id": 1001,
"title": "The Subtle Knife",
"authorId": 1000,
- "createdAt": "2023-11-30T11:55:24.996168+00:00"
+ "createdAt": "2024-01-08T11:50:21.50977+00:00"
},
{
"id": 1002,
"title": "The Amber Spyglass",
"authorId": 1000,
- "createdAt": "2023-11-30T11:55:24.996692+00:00"
+ "createdAt": "2024-01-08T11:50:21.510292+00:00"
}
]
@@ -1817,7 +1817,7 @@ select
, select
"id": 1003,
"title": "The Curious Incident of the Dog in the Night-Time",
"authorId": 1001,
- "createdAt": "2023-11-30T11:55:25.000887+00:00"
+ "createdAt": "2024-01-08T11:50:21.513693+00:00"
}
]
@@ -1840,7 +1840,7 @@ select
, select
"id": 1003,
"title": "The Curious Incident of the Dog in the Night-Time",
"authorId": 1001,
- "createdAt": "2023-11-30T11:55:25.000887+00:00"
+ "createdAt": "2024-01-08T11:50:21.513693+00:00"
}
]
@@ -1862,7 +1862,7 @@ select
, select
"id": 1,
"title": "A Brief History of Time",
"authorId": 5,
- "createdAt": "2023-11-30T11:56:09.395795+00:00"
+ "createdAt": "2024-01-08T11:51:15.452677+00:00"
}
]
@@ -1930,7 +1930,7 @@ order
, limit
and "id": 1,
"title": "A Brief History of Time",
"authorId": 5,
- "createdAt": "2023-11-30T11:56:09.395795+00:00"
+ "createdAt": "2024-01-08T11:51:15.452677+00:00"
}
]
@@ -1950,7 +1950,7 @@ order
, limit
and "id": 1,
"title": "A Brief History of Time",
"authorId": 5,
- "createdAt": "2023-11-30T11:56:09.395795+00:00"
+ "createdAt": "2024-01-08T11:51:15.452677+00: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 mapsdistinct
[
{
- "id": 1,
- "title": "A Brief History of Time",
- "authorId": 5,
- "createdAt": "2023-11-30T11:56:09.395795+00:00"
+ "id": 1002,
+ "title": "The Amber Spyglass",
+ "authorId": 1000,
+ "createdAt": "2024-01-08T11:50:21.510292+00:00"
},
{
"id": 1001,
"title": "The Subtle Knife",
"authorId": 1000,
- "createdAt": "2023-11-30T11:55:24.996168+00:00"
+ "createdAt": "2024-01-08T11:50:21.50977+00:00"
},
{
"id": 1003,
"title": "The Curious Incident of the Dog in the Night-Time",
"authorId": 1001,
- "createdAt": "2023-11-30T11:55:25.000887+00:00"
+ "createdAt": "2024-01-08T11:50:21.513693+00:00"
},
{
"id": 2,
"title": "My Brief History",
"authorId": 5,
- "createdAt": "2023-11-30T11:56:09.395795+00:00"
+ "createdAt": "2024-01-08T11:51:15.452677+00:00"
},
{
- "id": 1002,
- "title": "The Amber Spyglass",
+ "id": 1000,
+ "title": "Northern Lights",
"authorId": 1000,
- "createdAt": "2023-11-30T11:55:24.996692+00:00"
+ "createdAt": "2024-01-08T11:50:21.508324+00:00"
},
{
- "id": 3,
- "title": "The Universe in a Nutshell",
+ "id": 1,
+ "title": "A Brief History of Time",
"authorId": 5,
- "createdAt": "2023-11-30T11:56:09.400222+00:00"
+ "createdAt": "2024-01-08T11:51:15.452677+00:00"
},
{
- "id": 1000,
- "title": "Northern Lights",
- "authorId": 1000,
- "createdAt": "2023-11-30T11:55:24.995182+00:00"
+ "id": 3,
+ "title": "The Universe in a Nutshell",
+ "authorId": 5,
+ "createdAt": "2024-01-08T11:51:15.457539+00:00"
}
]
SELECT coalesce(jsonb_agg(result), '[]') AS result
@@ -2803,43 +2803,43 @@ distinct
"id": 1,
"title": "A Brief History of Time",
"authorId": 5,
- "createdAt": "2023-11-30T11:56:09.395795+00:00"
+ "createdAt": "2024-01-08T11:51:15.452677+00:00"
},
{
"id": 2,
"title": "My Brief History",
"authorId": 5,
- "createdAt": "2023-11-30T11:56:09.395795+00:00"
+ "createdAt": "2024-01-08T11:51:15.452677+00:00"
},
{
"id": 1000,
"title": "Northern Lights",
"authorId": 1000,
- "createdAt": "2023-11-30T11:55:24.995182+00:00"
+ "createdAt": "2024-01-08T11:50:21.508324+00:00"
},
{
"id": 1002,
"title": "The Amber Spyglass",
"authorId": 1000,
- "createdAt": "2023-11-30T11:55:24.996692+00:00"
+ "createdAt": "2024-01-08T11:50:21.510292+00:00"
},
{
"id": 1003,
"title": "The Curious Incident of the Dog in the Night-Time",
"authorId": 1001,
- "createdAt": "2023-11-30T11:55:25.000887+00:00"
+ "createdAt": "2024-01-08T11:50:21.513693+00:00"
},
{
"id": 1001,
"title": "The Subtle Knife",
"authorId": 1000,
- "createdAt": "2023-11-30T11:55:24.996168+00:00"
+ "createdAt": "2024-01-08T11:50:21.50977+00:00"
},
{
"id": 3,
"title": "The Universe in a Nutshell",
"authorId": 5,
- "createdAt": "2023-11-30T11:56:09.400222+00:00"
+ "createdAt": "2024-01-08T11:51:15.457539+00:00"
}
]
SELECT coalesce(jsonb_agg(result), '[]') AS result
@@ -2851,43 +2851,43 @@ distinct
"id": 1,
"title": "A Brief History of Time",
"authorId": 5,
- "createdAt": "2023-11-30T11:56:09.395795+00:00"
+ "createdAt": "2024-01-08T11:51:15.452677+00:00"
},
{
"id": 2,
"title": "My Brief History",
"authorId": 5,
- "createdAt": "2023-11-30T11:56:09.395795+00:00"
+ "createdAt": "2024-01-08T11:51:15.452677+00:00"
},
{
"id": 1000,
"title": "Northern Lights",
"authorId": 1000,
- "createdAt": "2023-11-30T11:55:24.995182+00:00"
+ "createdAt": "2024-01-08T11:50:21.508324+00:00"
},
{
"id": 1002,
"title": "The Amber Spyglass",
"authorId": 1000,
- "createdAt": "2023-11-30T11:55:24.996692+00:00"
+ "createdAt": "2024-01-08T11:50:21.510292+00:00"
},
{
"id": 1003,
"title": "The Curious Incident of the Dog in the Night-Time",
"authorId": 1001,
- "createdAt": "2023-11-30T11:55:25.000887+00:00"
+ "createdAt": "2024-01-08T11:50:21.513693+00:00"
},
{
"id": 1001,
"title": "The Subtle Knife",
"authorId": 1000,
- "createdAt": "2023-11-30T11:55:24.996168+00:00"
+ "createdAt": "2024-01-08T11:50:21.50977+00:00"
},
{
"id": 3,
"title": "The Universe in a Nutshell",
"authorId": 5,
- "createdAt": "2023-11-30T11:56:09.400222+00:00"
+ "createdAt": "2024-01-08T11:51:15.457539+00:00"
}
]
SELECT coalesce(jsonb_agg(result), '[]') AS result
@@ -2899,43 +2899,43 @@ distinct
"id": 1,
"title": "A Brief History of Time",
"authorId": 5,
- "createdAt": "2023-11-30T11:56:09.395795+00:00"
+ "createdAt": "2024-01-08T11:51:15.452677+00:00"
},
{
"id": 2,
"title": "My Brief History",
"authorId": 5,
- "createdAt": "2023-11-30T11:56:09.395795+00:00"
+ "createdAt": "2024-01-08T11:51:15.452677+00:00"
},
{
"id": 1000,
"title": "Northern Lights",
"authorId": 1000,
- "createdAt": "2023-11-30T11:55:24.995182+00:00"
+ "createdAt": "2024-01-08T11:50:21.508324+00:00"
},
{
"id": 1002,
"title": "The Amber Spyglass",
"authorId": 1000,
- "createdAt": "2023-11-30T11:55:24.996692+00:00"
+ "createdAt": "2024-01-08T11:50:21.510292+00:00"
},
{
"id": 1003,
"title": "The Curious Incident of the Dog in the Night-Time",
"authorId": 1001,
- "createdAt": "2023-11-30T11:55:25.000887+00:00"
+ "createdAt": "2024-01-08T11:50:21.513693+00:00"
},
{
"id": 1001,
"title": "The Subtle Knife",
"authorId": 1000,
- "createdAt": "2023-11-30T11:55:24.996168+00:00"
+ "createdAt": "2024-01-08T11:50:21.50977+00:00"
},
{
"id": 3,
"title": "The Universe in a Nutshell",
"authorId": 5,
- "createdAt": "2023-11-30T11:56:09.400222+00:00"
+ "createdAt": "2024-01-08T11:51:15.457539+00:00"
}
]
@@ -3094,7 +3094,7 @@ JSONSelectable
JSONSelectable
transaction
ROLLBACK
, release the database client (if it’s one it checked out earlier), and re-throw the error.COMMIT
the transaction, release the database client (if it’s one it checked out earlier), and return the callback’s result.As is implied above, for REPEATABLE READ
or SYNCHRONIZED
isolation modes the callback could be called several times. It’s therefore important that it doesn’t have any non-database-related side-effects (i.e. don’t, say, bill your customer’s credit card from this function).
As is implied above, for REPEATABLE READ
or SERIALIZABLE
isolation modes the callback could be called several times. It’s therefore important that it doesn’t have any non-database-related side-effects (i.e. don’t, say, bill your customer’s credit card from this function).
We already saw one transaction
example. Here’s another, adapted from CockroachDB’s write-up on SERIALIZABLE
.
We have a table of doctors
, and a table of their assigned shifts
.
CREATE TABLE "doctors"
@@ -3420,7 +3448,7 @@ transaction
Transaction 1
ROLLBACK
Transaction 1
-Transaction rollback (code 40001) on attempt 1 of 5, retrying in 76ms
+Transaction rollback (code 40001) on attempt 1 of 5, retrying in 151ms
Transaction 1
Retrying transaction, attempt 2 of 5
Transaction 1