All Projects → denizzzka → dpq2

denizzzka / dpq2

Licence: BSL-1.0 License
This is yet another attempt to create a good interface to PostgreSQL for the D programming language.

Programming Languages

d
599 projects

Projects that are alternatives of or similar to dpq2

libpq.framework
An XCode project to compile your own libpq.framework for iOS 11.x
Stars: ✭ 27 (-51.79%)
Mutual labels:  postgres, libpq
Node Postgres
PostgreSQL client for node.js.
Stars: ✭ 10,061 (+17866.07%)
Mutual labels:  postgres, libpq
Serilog.Sinks.Postgresql.Alternative
Serilog.Sinks.Postgresql.Alternative is a library to save logging information from https://github.com/serilog/serilog to https://www.postgresql.org/.
Stars: ✭ 29 (-48.21%)
Mutual labels:  postgres
vscode-database
Extension for Visual Studio Code
Stars: ✭ 132 (+135.71%)
Mutual labels:  postgres
docker-postgres-windows
No description or website provided.
Stars: ✭ 19 (-66.07%)
Mutual labels:  postgres
amcheck
contrib/amcheck from Postgres v11 backported to earlier Postgres versions
Stars: ✭ 74 (+32.14%)
Mutual labels:  postgres
oesophagus
Enterprise Grade Single-Step Streaming Data Infrastructure Setup. (Under Development)
Stars: ✭ 12 (-78.57%)
Mutual labels:  postgres
benchmark
Parse Server Continuous Benchmark
Stars: ✭ 21 (-62.5%)
Mutual labels:  postgres
go-grpc-pg
Simple service exposing a gRPC interface, with a connection to PostgreSQL on the backend
Stars: ✭ 33 (-41.07%)
Mutual labels:  postgres
astro
Astro allows rapid and clean development of {Extract, Load, Transform} workflows using Python and SQL, powered by Apache Airflow.
Stars: ✭ 79 (+41.07%)
Mutual labels:  postgres
pggen
Generate type-safe Go for any Postgres query. If Postgres can run the query, pggen can generate code for it.
Stars: ✭ 151 (+169.64%)
Mutual labels:  postgres
pg-audit-json
Simple, easily customised trigger-based auditing for PostgreSQL (Postgres). See also pgaudit.
Stars: ✭ 34 (-39.29%)
Mutual labels:  postgres
teanjs
🔥 TypeORM - Express - Angular 8 - NestJS Server Side Rendering (SSR) 😺
Stars: ✭ 62 (+10.71%)
Mutual labels:  postgres
nebulo
Instant GraphQL API for PostgreSQL and SQLAlchemy
Stars: ✭ 74 (+32.14%)
Mutual labels:  postgres
mathesar
Web application providing an intuitive user experience to databases.
Stars: ✭ 95 (+69.64%)
Mutual labels:  postgres
subsocial-offchain
Off-chain storage for Subsocial blockchain. This app builds user feeds and notifications by subscribing to Substrate events.
Stars: ✭ 24 (-57.14%)
Mutual labels:  postgres
fastapi-starter
A FastAPI based low code starter: Async SQLAlchemy, Postgres, React-Admin, pytest and cypress
Stars: ✭ 97 (+73.21%)
Mutual labels:  postgres
postgres exporter
Postgres exporter
Stars: ✭ 14 (-75%)
Mutual labels:  postgres
plow
👨‍🌾 Postgres migrations and seeding made easy
Stars: ✭ 13 (-76.79%)
Mutual labels:  postgres
Myongstagram-ReactNative
⭐ Instagram Clone with React Native + Redux + Expo + Node.js + Postgres
Stars: ✭ 19 (-66.07%)
Mutual labels:  postgres

dpq2

Build Status Coverage Status codecov.io

This is yet another attempt to create a good interface to PostgreSQL for the D programming language.

It adds only tiny overhead to the original low level library libpq but make convenient use PostgreSQL from D.

API documentation

Please help us to make documentation better!

Features

  • Text string arguments support
  • Binary arguments support (including multi-dimensional arrays)
  • Both text and binary formats of query result support
  • Immutable query result for simplify multithreading
  • Async queries support
  • Reading of the text query results to native D text types
  • Representation of binary arguments and binary query results as native D types
  • Text types
  • Integer and decimal types
  • Money type (into money.currency, https://github.com/dlang-community/d-money)
  • Some data and time types
  • JSON type (stored into vibe.data.json.Json)
  • JSONB type (ditto)
  • Geometric types
  • Conversion of values to BSON (into vibe.data.bson.Bson)
  • Access to PostgreSQL's multidimensional arrays
  • LISTEN/NOTIFY support
  • Bulk data upload to table from string data (SQL COPY)
  • Simple SQL query builder

Building

Bindings for libpq can be static or dynamic.

The static bindings are generated by default. Add --config=dynamic to the dub parameters to generate dynamic bindings.

Example

#!/usr/bin/env rdmd

import dpq2;
import std.getopt;
import std.stdio: writeln;
import std.typecons: Nullable;
import vibe.data.bson;

void main(string[] args)
{
    string connInfo;
    getopt(args, "conninfo", &connInfo);

    Connection conn = new Connection(connInfo);

    // Only text query result can be obtained by this call:
    auto answer = conn.exec(
        "SELECT now()::timestamp as current_time, 'abc'::text as field_name, "~
        "123 as field_3, 456.78 as field_4, '{\"JSON field name\": 123.456}'::json"
        );

    writeln( "Text query result by name: ", answer[0]["current_time"].as!PGtext );
    writeln( "Text query result by index: ", answer[0][3].as!PGtext );

    // It is possible to read values of unknown type using BSON:
    auto firstRow = answer[0];
    foreach(cell; rangify(firstRow))
    {
        writeln("bson: ", cell.as!Bson);
    }

    // Binary arguments query with binary result:
    QueryParams p;
    p.sqlCommand = "SELECT "~
        "$1::double precision as double_field, "~
        "$2::text, "~
        "$3::text as null_field, "~
        "array['first', 'second', NULL]::text[] as array_field, "~
        "$4::integer[] as multi_array, "~
        "'{\"float_value\": 123.456,\"text_str\": \"text string\"}'::json as json_value";

    p.argsVariadic(
        -1234.56789012345,
        "first line\nsecond line",
        Nullable!string.init,
        [[1, 2, 3], [4, 5, 6]]
    );

    auto r = conn.execParams(p);
    scope(exit) destroy(r);

    writeln( "0: ", r[0]["double_field"].as!PGdouble_precision );
    writeln( "1: ", r[0][1].as!PGtext );
    writeln( "2.1 isNull: ", r[0][2].isNull );
    writeln( "2.2 isNULL: ", r[0].isNULL(2) );
    writeln( "3.1: ", r[0][3].asArray[0].as!PGtext );
    writeln( "3.2: ", r[0][3].asArray[1].as!PGtext );
    writeln( "3.3: ", r[0]["array_field"].asArray[2].isNull );
    writeln( "3.4: ", r[0]["array_field"].asArray.isNULL(2) );
    writeln( "4.1: ", r[0]["multi_array"].asArray.getValue(1, 2).as!PGinteger );
    writeln( "4.2: ", r[0]["multi_array"].as!(int[][]) );
    writeln( "5.1 Json: ", r[0]["json_value"].as!Json);
    writeln( "5.2 Bson: ", r[0]["json_value"].as!Bson);

    // It is possible to read values of unknown type using BSON:
    for(auto column = 0; column < r.columnCount; column++)
    {
        writeln("column name: '"~r.columnName(column)~"', bson: ", r[0][column].as!Bson);
    }

    // It is possible to upload CSV data ultra-fast:
    conn.exec("CREATE TEMP TABLE test_dpq2_copy (v1 TEXT, v2 INT)");

    // Init the COPY command. This sets the connection in a COPY receive
    // mode until putCopyEnd() is called. Copy CSV data, because it's standard,
    // ultra fast, and readable:
    conn.exec("COPY test_dpq2_copy FROM STDIN WITH (FORMAT csv)");

    // Write 2 lines of CSV, including text that contains the delimiter.
    // Postgresql handles it well:
    string data = "\"This, right here, is a test\",8\nWow! it works,13\n";
    conn.putCopyData(data);

    // Write 2 more lines
    data = "Horray!,3456\nSuper fast!,325\n";
    conn.putCopyData(data);

    // Signal that the COPY is finished. Let Postgresql finalize the command
    // and return any errors with the data.
    conn.putCopyEnd();
}

Compile and run:

Running ./dpq2_example --conninfo=user=postgres
2018-12-09T10:08:07.862:package.d:__lambda1:19 DerelictPQ loading...
2018-12-09T10:08:07.863:package.d:__lambda1:26 ...DerelictPQ loading finished
Text query result by name: 2018-12-09 10:08:07.868141
Text query result by index: 456.78
bson: "2018-12-09 10:08:07.868141"
bson: "abc"
bson: "123"
bson: "456.78"
bson: {"JSON field name":123.456}
0: -1234.57
1: first line
second line
2.1 isNull: true
2.2 isNULL: true
3.1: first
3.2: second
3.3: true
3.4: true
4.1: 6
4.2: [[1, 2, 3], [4, 5, 6]]
5.1 Json: {"text_str":"text string","float_value":123.456}
5.2 Bson: {"text_str":"text string","float_value":123.456}
column name: 'double_field', bson: -1234.56789012345
column name: 'text', bson: "first line\nsecond line"
column name: 'null_field', bson: null
column name: 'array_field', bson: ["first","second",null]
column name: 'multi_array', bson: [[1,2,3],[4,5,6]]
column name: 'json_value', bson: {"text_str":"text string","float_value":123.456}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].