vibe.d + dpq2 + json trick
Denis Feklushkin
feklushkin.denis at gmail.com
Wed Aug 20 12:24:12 UTC 2025
On Tuesday, 19 August 2025 at 14:09:09 UTC, Robert Schadek wrote:
> While working on other stuff I thought why should I have to
> press the DB response into json in vibe at all, as Postgres can
> generate json?
It would also be nice to measure the time it takes to get a
response from Postgres.
As for me, Postgres server is too expensive resource for this
work, even though this particular query works faster for some
reason. Getting a result near to a "tabular binary form" from PG,
we can convert it in into JSON on D side which code can work in
parallel on several (or hundreds) servers.
> Looking into it, it turns out that libpg which is used by dpq2
> returns json as a string.
Strictly speaking, PG supports two JSON types: json and jsonb
("indexed" form of json with additional offset values). It might
be worth experimenting with changing it to "jsonb" type to
achieve performance improvement
> foreach(ref it; result) {
> pIds ~= Person(it["id"].as!(long)());
> }
libpq calls "id"->col number conversion for each time here. This,
of course, is fast, but...
More information about the Digitalmars-d
mailing list