Browse Source

init - vibe-d postgresql driver with pool - example 1

221V 6 days ago
parent
commit
dba71b3a11
4 changed files with 55 additions and 4 deletions
  1. 9 0
      README.md
  2. 5 2
      vtest/dub.json
  3. 6 1
      vtest/dub.selections.json
  4. 35 1
      vtest/source/app.d

+ 9 - 0
README.md

@@ -20,6 +20,15 @@
 "mustache-d": "~>0.1.5"
 
 
+because gssapi_krb5 not supports static linking - use dynamics linking for it
+ls /usr/lib/x86_64-linux-gnu/libgssapi_krb5*
+/usr/lib/x86_64-linux-gnu/libgssapi_krb5.so@  /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2@  /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2.2
+
+so delete -static
+"dflags": ["-w", "-O", "-static"],
+
+sudo apt update
+sudo apt-get install libpq-dev libpq5 libldap2-dev libssl-dev libkrb5-dev
 
 sudo apt-get install libevent-dev
 sudo apt-get install libmemcached-dev

+ 5 - 2
vtest/dub.json

@@ -3,8 +3,8 @@
   "description": "A simple vibe.d server application.",
   
   "targetName": "vtest",
-  "dflags": ["-w", "-O", "-static"],
   "targetType": "executable",
+  "dflags": ["-w", "-O"],
   "dependencies": {
     "vibe-inet:crypto": "~>1.1.2",
     "vibe-inet": "~>1.1.2",
@@ -12,8 +12,11 @@
     "vibe-stream": "~>1.1.1",
     "vibe-inet:textfilter": "~>1.1.2",
     
-    "mustache-d": "~>0.1.5"
+    "mustache-d": "~>0.1.5",
+    "vibe-d-postgresql": "~>3.1.3"
   },
+  "libs": ["pq", "ssl", "crypto", "ldap", "gssapi_krb5"],
+  "lflags": [],
   
   "license": "proprietary",
   "copyright": "Copyright © 2025, 221V",

+ 6 - 1
vtest/dub.selections.json

@@ -1,8 +1,12 @@
 {
 	"fileVersion": 1,
 	"versions": {
+		"derelict-pq": "4.0.0",
+		"derelict-util": "3.0.0-beta.2",
+		"dpq2": "1.1.7",
 		"eventcore": "0.9.35",
 		"mir-linux-kernel": "1.2.1",
+		"money": "3.0.2",
 		"mustache-d": "0.1.5",
 		"openssl": "3.3.4",
 		"openssl-static": "1.0.5+3.0.8",
@@ -10,7 +14,8 @@
 		"taggedalgebraic": "0.11.23",
 		"vibe-container": "1.6.2",
 		"vibe-core": "2.11.0",
-		"vibe-http": "1.2.2",
+		"vibe-d": "0.10.2",
+		"vibe-d-postgresql": "3.1.3",
 		"vibe-inet": "1.1.2",
 		"vibe-serialization": "1.1.1",
 		"vibe-stream": "1.1.1"

+ 35 - 1
vtest/source/app.d

@@ -25,6 +25,13 @@ import mustache;
 alias MustacheEngine!(string) Mustache;
 
 
+import vibe.db.postgresql;
+import vibe.data.bson;
+//import vibe.data.json;
+// https://github.com/vibe-d/vibe.d/blob/master/source/vibe/vibe.d
+
+PostgresClient client;
+
 
 /* test unproper arguments order */
 /* do not */
@@ -124,6 +131,26 @@ void hello(HTTPServerRequest req, HTTPServerResponse res){
 */
 
 
+void test_pg_conn_driver(){
+  client.pickConnection( (scope conn){
+    immutable result = conn.execStatement(
+      "SELECT 123 as first_num, 567 as second_num, 'abc'::text as third_text " ~
+      "UNION ALL " ~
+      "SELECT 890, 233, 'fgh'::text as third_text",
+      ValueFormat.BINARY
+    );
+    
+    assert(result[0]["second_num"].as!PGinteger == 567);
+    assert(result[1]["third_text"].as!PGtext == "fgh");
+    
+    foreach (val; rangify(result[0])){
+      writeln("Found entry: ", val.as!Bson.toJson);
+    }
+  } );
+}
+
+
+
 void test(HTTPServerRequest req, HTTPServerResponse res){
   auto cache = memcachedConnect("127.0.0.1:11211");
   
@@ -193,6 +220,14 @@ void test(HTTPServerRequest req, HTTPServerResponse res){
   
   
   
+  // https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
+  // https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS
+  //client = new PostgresClient("host=localhost port=5432 dbname=mydb user=usename password=pass connect_timeout=5", 100);
+  client = new PostgresClient("host=195.201.41.112 port=5432 dbname=t4x_parser_data user=admin4 password=Ftsn3rT5YA6ZDWEywfmXekKCS8a4cNxp connect_timeout=5", 100);
+  test_pg_conn_driver();
+  
+  
+  
   Mustache mustache2;
   auto context2 = new Mustache.Context;
   mustache2.path = "priv/folder2";
@@ -226,4 +261,3 @@ void test(HTTPServerRequest req, HTTPServerResponse res){
   res.writeBody( mustache.render("main", context) );
 }
 
-