www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - question on dub and postgresql

reply Alaindevos <devosalain ymail.com> writes:
Can I say python has pip, ruby has bundle and D has dub.
Meaning they perform the same function ?
Or am I wrong?

As I use unix the parameters for include and library are a real 
pain.
I have totally no idea how to connect to a postgresql database.
Where and how do I start to connect to a postgresql database ?
I write a .d program to connect.
But then I need to include the database-connection-library.d file.
Where do I place it ?
And link a database-connection. object file.
How is it installed ? There is a only a git i can clone ?
Do I need to create and edit a specific dub json config file ?
It is very unclear how to start.

[Cfr. in python it is just a "pip install postgres". And you're 
fine ]
Thanks for any info.
Oct 05 2020
next sibling parent Alaindevos <devosalain ymail.com> writes:
On Monday, 5 October 2020 at 08:24:26 UTC, Alaindevos wrote:
 Can I say python has pip, ruby has bundle and D has dub.
 Meaning they perform the same function ?
 Or am I wrong?

 As I use unix the parameters for include and library are a real 
 pain.
 I have totally no idea how to connect to a postgresql database.
 Where and how do I start to connect to a postgresql database ?
 I write a .d program to connect.
 But then I need to include the database-connection-library.d 
 file.
 Where do I place it ?
 And link a database-connection. object file.
 How is it installed ? There is a only a git i can clone ?
 Do I need to create and edit a specific dub json config file ?
 It is very unclear how to start.

 [Cfr. in python it is just a "pip install postgres". And you're 
 fine ]
 Thanks for any info.
Some additional question, i struggle with. Do i run dub make dub install on git clone ? Or make , make install ? Or it depends on the package provider ? What for vibe ? Which postgresql implementation is best for retreving query results record by record ?
Oct 05 2020
prev sibling next sibling parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Monday, 5 October 2020 at 08:24:26 UTC, Alaindevos wrote:
 Can I say python has pip, ruby has bundle and D has dub.
 Meaning they perform the same function ?
 Or am I wrong?

 As I use unix the parameters for include and library are a real 
 pain.
 I have totally no idea how to connect to a postgresql database.
 Where and how do I start to connect to a postgresql database ?
 I write a .d program to connect.
 But then I need to include the database-connection-library.d 
 file.
 Where do I place it ?
 And link a database-connection. object file.
 How is it installed ? There is a only a git i can clone ?
 Do I need to create and edit a specific dub json config file ?
 It is very unclear how to start.

 [Cfr. in python it is just a "pip install postgres". And you're 
 fine ]
 Thanks for any info.
Take a look at: https://code.dlang.org/packages/dpq2 https://code.dlang.org/packages/ddbc
Oct 05 2020
parent reply Alaindevos <devosalain ymail.com> writes:
On Monday, 5 October 2020 at 08:34:37 UTC, Imperatorn wrote:
 On Monday, 5 October 2020 at 08:24:26 UTC, Alaindevos wrote:
 [...]
Take a look at: https://code.dlang.org/packages/dpq2 https://code.dlang.org/packages/ddbc
Say I want to use dpq2. Do I need to clone the git repository with "git clone ?"
Oct 05 2020
next sibling parent reply Alaindevos <devosalain ymail.com> writes:
On Monday, 5 October 2020 at 08:47:45 UTC, Alaindevos wrote:
 On Monday, 5 October 2020 at 08:34:37 UTC, Imperatorn wrote:
 On Monday, 5 October 2020 at 08:24:26 UTC, Alaindevos wrote:
 [...]
Take a look at: https://code.dlang.org/packages/dpq2 https://code.dlang.org/packages/ddbc
Say I want to use dpq2. Do I need to clone the git repository with "git clone ?"
rdmd is as expected unaware of includes and libraries needed. rdmd --build-only test.d test.d(3): Error: module `dpq2` is in file 'dpq2.d' which cannot be read import path[0] = . import path[1] = /usr/local/include/d Failed: ["/usr/local/bin/ldmd2", "-v", "-o-", "test.d", "-I."]
Oct 05 2020
parent Alaindevos <devosalain ymail.com> writes:
On Monday, 5 October 2020 at 08:50:53 UTC, Alaindevos wrote:
 On Monday, 5 October 2020 at 08:47:45 UTC, Alaindevos wrote:
 On Monday, 5 October 2020 at 08:34:37 UTC, Imperatorn wrote:
 On Monday, 5 October 2020 at 08:24:26 UTC, Alaindevos wrote:
 [...]
Take a look at: https://code.dlang.org/packages/dpq2 https://code.dlang.org/packages/ddbc
Say I want to use dpq2. Do I need to clone the git repository with "git clone ?"
rdmd is as expected unaware of includes and libraries needed. rdmd --build-only test.d test.d(3): Error: module `dpq2` is in file 'dpq2.d' which cannot be read import path[0] = . import path[1] = /usr/local/include/d Failed: ["/usr/local/bin/ldmd2", "-v", "-o-", "test.d", "-I."]
I cloned the git repository with ,running make does nothing. There is no makefile. Dub build spits out, dub build (git)-[master]- Main package must not have target type "sourceLibrary". Cannot build.
Oct 05 2020
prev sibling parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Monday, 5 October 2020 at 08:47:45 UTC, Alaindevos wrote:
 On Monday, 5 October 2020 at 08:34:37 UTC, Imperatorn wrote:
 On Monday, 5 October 2020 at 08:24:26 UTC, Alaindevos wrote:
 [...]
Take a look at: https://code.dlang.org/packages/dpq2 https://code.dlang.org/packages/ddbc
Say I want to use dpq2. Do I need to clone the git repository with "git clone ?"
No, you just dub add dpq2
Oct 05 2020
parent reply Alaindevos <devosalain ymail.com> writes:
On Monday, 5 October 2020 at 11:35:43 UTC, Imperatorn wrote:
 On Monday, 5 October 2020 at 08:47:45 UTC, Alaindevos wrote:
 On Monday, 5 October 2020 at 08:34:37 UTC, Imperatorn wrote:
 On Monday, 5 October 2020 at 08:24:26 UTC, Alaindevos wrote:
 [...]
Take a look at: https://code.dlang.org/packages/dpq2 https://code.dlang.org/packages/ddbc
Say I want to use dpq2. Do I need to clone the git repository with "git clone ?"
No, you just dub add dpq2
With dub.json: "dependencies": { "dpq2": "~>1.0.17" }, It worked. Something I ask myself is how do I pass a connection from one function to another. ... string url=format("hostaddr='127.0.0.1' port='5432' dbname='%s' user='%s' password='%s'",db,user,pass); writeln(url); Connection conn = new Connection(url); auto answer = conn.exec("SELECT version()"); writeln(answer[0][0].as!PGtext); ... myfunction(conn) void myfunction( .... conn) What is the type I should use for passing conn ?
Oct 05 2020
next sibling parent reply Alaindevos <devosalain ymail.com> writes:
On Monday, 5 October 2020 at 13:30:22 UTC, Alaindevos wrote:
 On Monday, 5 October 2020 at 11:35:43 UTC, Imperatorn wrote:
 On Monday, 5 October 2020 at 08:47:45 UTC, Alaindevos wrote:
 On Monday, 5 October 2020 at 08:34:37 UTC, Imperatorn wrote:
 On Monday, 5 October 2020 at 08:24:26 UTC, Alaindevos wrote:
 [...]
Take a look at: https://code.dlang.org/packages/dpq2 https://code.dlang.org/packages/ddbc
Say I want to use dpq2. Do I need to clone the git repository with "git clone ?"
No, you just dub add dpq2
With dub.json: "dependencies": { "dpq2": "~>1.0.17" }, It worked. Something I ask myself is how do I pass a connection from one function to another. ... string url=format("hostaddr='127.0.0.1' port='5432' dbname='%s' user='%s' password='%s'",db,user,pass); writeln(url); Connection conn = new Connection(url); auto answer = conn.exec("SELECT version()"); writeln(answer[0][0].as!PGtext); ... myfunction(conn) void myfunction( .... conn) What is the type I should use for passing conn ?
Maybe just Connection ?
Oct 05 2020
parent reply Alaindevos <devosalain ymail.com> writes:
Just Connection worked.
But how do I loop over results of a select statement.
string sql=format(" SELECT * from %s ;",tablepredata);
auto answer = conn.exec(sql);
foreach(arow; answer){
	writeln(arow);
}
Fails with,
dub ~master: building configuration "application"...
source/app.d(36,3): Error: invalid foreach aggregate answer, 
define opApply(), range primitives, or use .tupleof
/usr/local/bin/ldc2 failed with exit code 1.
Oct 05 2020
parent reply Alaindevos <devosalain ymail.com> writes:
answer[0][0].as!PGtext contains good data
Oct 05 2020
parent reply Alaindevos <devosalain ymail.com> writes:
On Monday, 5 October 2020 at 14:57:53 UTC, Alaindevos wrote:
 answer[0][0].as!PGtext contains good data
I found an answer.

foreach(rownumber; answer.length.iota){
auto arow=answer[rownumber];
writeln(arow);
}

Yet it would be nice to know why i can't iterate directly over 
answer using foreach.
Oct 05 2020
next sibling parent Mike Parker <aldacron gmail.com> writes:
On Monday, 5 October 2020 at 15:08:54 UTC, Alaindevos wrote:


 Yet it would be nice to know why i can't iterate directly over 
 answer using foreach.
Looking at the implementation of the `Answer` type [1], I see no way to create a range or a slice, and no `opApply`. So you'll have to ask the maintainer about that. [1] https://github.com/denizzzka/dpq2/blob/master/src/dpq2/result.d#L107
Oct 05 2020
prev sibling parent reply Denis Feklushkin <feklushkin.denis gmail.com> writes:
On Monday, 5 October 2020 at 15:08:54 UTC, Alaindevos wrote:
 On Monday, 5 October 2020 at 14:57:53 UTC, Alaindevos wrote:
 answer[0][0].as!PGtext contains good data
I found an answer.

 foreach(rownumber; answer.length.iota){
 auto arow=answer[rownumber];
 writeln(arow);
 }

 Yet it would be nice to know why i can't iterate directly over 
 answer using foreach.
Use "rangify" template to get forward range from answer
Oct 05 2020
parent reply Alaindevos <devosalain ymail.com> writes:
 Use "rangify" template to get forward range from answer
Thanks, this answers the question on programmatic level. Yet I guess something is special with the answer datatype which makes foreach to fail.
Oct 05 2020
parent James Blachly <james.blachly gmail.com> writes:
On 10/5/20 11:42 AM, Alaindevos wrote:
 Use "rangify" template to get forward range from answer
Thanks, this answers the question on programmatic level. Yet I guess something is special with the answer datatype which makes foreach to fail.
Instead of thinking of it as "foreach failing," instead consider that the library author did not implement foreach.
Oct 05 2020
prev sibling parent Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Monday, 5 October 2020 at 13:30:22 UTC, Alaindevos wrote:
 On Monday, 5 October 2020 at 11:35:43 UTC, Imperatorn wrote:
 On Monday, 5 October 2020 at 08:47:45 UTC, Alaindevos wrote:
 [...]
No, you just dub add dpq2
With dub.json: "dependencies": { "dpq2": "~>1.0.17" }, It worked. Something I ask myself is how do I pass a connection from one function to another. ... string url=format("hostaddr='127.0.0.1' port='5432' dbname='%s' user='%s' password='%s'",db,user,pass); writeln(url); Connection conn = new Connection(url); auto answer = conn.exec("SELECT version()"); writeln(answer[0][0].as!PGtext); ... myfunction(conn) void myfunction( .... conn) What is the type I should use for passing conn ?
Is this the first time you are trying D?
Oct 05 2020
prev sibling parent reply Daniel Kozak <kozzi11 gmail.com> writes:
On Mon, Oct 5, 2020 at 10:25 AM Alaindevos via Digitalmars-d-learn <
digitalmars-d-learn puremagic.com> wrote:

 Can I say python has pip, ruby has bundle and D has dub.
 Meaning they perform the same function ?
 Or am I wrong?
Yes and no. Dub is Dlang dependency solution but it is not installer as pip is
 As I use unix the parameters for include and library are a real
 pain.
 I have totally no idea how to connect to a postgresql database.
 Where and how do I start to connect to a postgresql database ?
 I write a .d program to connect.
 But then I need to include the database-connection-library.d file.
 Where do I place it ?
 And link a database-connection. object file.
 How is it installed ? There is a only a git i can clone ?
 Do I need to create and edit a specific dub json config file ?
 It is very unclear how to start.
Yes if you want to use any of dub packages you need to add it as a dependency to your dub.json (dub.sdl)
Oct 05 2020
parent reply Alaindevos <devosalain ymail.com> writes:
On Monday, 5 October 2020 at 08:54:39 UTC, Daniel Kozak wrote:
 On Mon, Oct 5, 2020 at 10:25 AM Alaindevos via 
 Digitalmars-d-learn < digitalmars-d-learn puremagic.com> wrote:

 Can I say python has pip, ruby has bundle and D has dub.
 Meaning they perform the same function ?
 Or am I wrong?
Yes and no. Dub is Dlang dependency solution but it is not installer as pip is
 As I use unix the parameters for include and library are a real
 pain.
 I have totally no idea how to connect to a postgresql database.
 Where and how do I start to connect to a postgresql database ?
 I write a .d program to connect.
 But then I need to include the database-connection-library.d 
 file.
 Where do I place it ?
 And link a database-connection. object file.
 How is it installed ? There is a only a git i can clone ?
 Do I need to create and edit a specific dub json config file ?
 It is very unclear how to start.
Yes if you want to use any of dub packages you need to add it as a dependency to your dub.json (dub.sdl)
A name dependency solution is at least vage. How do I install , https://github.com/denizzzka/dpq2 on unix so in the code i write the .d files of that library and after compilation linked to the libary shared objects. For that shared object must be installed. How ?
Oct 05 2020
next sibling parent drug <drug2004 bk.ru> writes:
On 10/5/20 12:05 PM, Alaindevos wrote:
 On Monday, 5 October 2020 at 08:54:39 UTC, Daniel Kozak wrote:
 On Mon, Oct 5, 2020 at 10:25 AM Alaindevos via Digitalmars-d-learn < 
 digitalmars-d-learn puremagic.com> wrote:

 Can I say python has pip, ruby has bundle and D has dub.
 Meaning they perform the same function ?
 Or am I wrong?
Yes and no. Dub is Dlang dependency solution but it is not installer as pip is
 As I use unix the parameters for include and library are a real
 pain.
 I have totally no idea how to connect to a postgresql database.
 Where and how do I start to connect to a postgresql database ?
 I write a .d program to connect.
 But then I need to include the database-connection-library.d file.
 Where do I place it ?
 And link a database-connection. object file.
 How is it installed ? There is a only a git i can clone ?
 Do I need to create and edit a specific dub json config file ?
 It is very unclear how to start.
Yes if you want to use any of dub packages you need to add it as a dependency to your dub.json (dub.sdl)
A name dependency solution is at least vage. How do I install , https://github.com/denizzzka/dpq2 on unix so in the code i write the .d files of that library and after compilation linked to the libary shared objects. For that shared object must be installed. How ?
Take a look at https://code.dlang.org/packages/dpq2 This is how packages work in D To add dpq2 dependency to your project you need to execute the command: ``` dub add dpq2 ``` it adds the last version of the dpq2 package. After this you are able to use this package in your project just import it in your source files.
Oct 05 2020
prev sibling next sibling parent reply Mike Parker <aldacron gmail.com> writes:
On Monday, 5 October 2020 at 09:05:16 UTC, Alaindevos wrote:

 A name dependency solution is at least vage.
 How do I install ,
 https://github.com/denizzzka/dpq2
 on unix so in the code i write the .d files of that library and 
 after compilation linked to the libary shared objects. For that 
 shared object must be installed. How ?
You don't need to install dpq2 if you are using dub to build your project. Add it as a dependency to your dub.json (or dub.sdl if you prefer that format). When you build your project, dub will download the version you configured as your dependency and compile it along with your project. In your project root directory (where your dub.json/sdl is located), you should be able to run `dub add dpq2` and dub will add the dependency to your configuration. Or you can add it manually. For dub.json: "dependencies": { "dpq2": "~>1.0.17" } For dub.sdl: dependency "dpq2" version="~>1.0.17" Make sure libpq is installed on your system and you should be good to go. See: https://code.dlang.org/packages/dpq2 https://dub.pm/package-format-json https://dub.pm/package-format-sdl If you aren't using dub to build your project, then you could potentially use `dub install dpq2` and it will install it in a cache folder which, IIRC, should be in ~/.dub. However, I would use `git clone` or `dub fetch` so that you can keep it in a specific folder. I have some instructions for using my old Derelict packages when you aren't using dub for your project. You can adapt that to dpq2: http://derelictorg.github.io/building/without-dub/ Once you've pulled down dpq2, you'll need to build it, then when building your project you'll have to pass the dpq source path to the compiler (with the -Ipath) so it can find the imports, the path to the dpq library you built (with -L-Lpath), and the dpq library (-L-ldpq).
Oct 05 2020
parent reply Alaindevos <devosalain ymail.com> writes:
On Monday, 5 October 2020 at 09:24:33 UTC, Mike Parker wrote:
 On Monday, 5 October 2020 at 09:05:16 UTC, Alaindevos wrote:

 [...]
You don't need to install dpq2 if you are using dub to build your project. Add it as a dependency to your dub.json (or dub.sdl if you prefer that format). When you build your project, dub will download the version you configured as your dependency and compile it along with your project. [...]
Thanks for this clear explanation. I'll try first using the dub tooling. PS : Manual does not look easy with different versions in the /home/myhome/.dub/packages directory.
Oct 05 2020
parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 10/5/20 6:01 AM, Alaindevos wrote:
 On Monday, 5 October 2020 at 09:24:33 UTC, Mike Parker wrote:
 On Monday, 5 October 2020 at 09:05:16 UTC, Alaindevos wrote:

 [...]
You don't need to install dpq2 if you are using dub to build your project. Add it as a dependency to your dub.json (or dub.sdl if you prefer that format). When you build your project, dub will download the version you configured as your dependency and compile it along with your project. [...]
Thanks for this clear explanation. I'll try first using the dub tooling. PS : Manual does not look easy with different versions in the /home/myhome/.dub/packages directory.
dub will automatically download any version that is used as a dependency. You don't have to worry about it. So let's say one project depends on version 2.0.0 of a package, and another depends on 1.0.0. Both will be downloaded, compiled, and used as the appropriate dependency that the project requests. Compare to a build system where you need to install the dependencies manually, now you have to install the right one to get the right version. However, keep in mind that dub only deals with D packages, not external dependencies (like libpq, which is required for dpq2). -Steve
Oct 05 2020
prev sibling parent reply aberba <karabutaworld gmail.com> writes:
On Monday, 5 October 2020 at 09:05:16 UTC, Alaindevos wrote:
 On Monday, 5 October 2020 at 08:54:39 UTC, Daniel Kozak wrote:
 On Mon, Oct 5, 2020 at 10:25 AM Alaindevos via 
 Digitalmars-d-learn < digitalmars-d-learn puremagic.com> wrote:

[...]
Yes and no. Dub is Dlang dependency solution but it is not installer as pip is
[...]
Yes if you want to use any of dub packages you need to add it as a dependency to your dub.json (dub.sdl)
A name dependency solution is at least vage. How do I install , https://github.com/denizzzka/dpq2 on unix so in the code i write the .d files of that library and after compilation linked to the libary shared objects. For that shared object must be installed. How ?
It seems the D ecosystem is not immediately obvious to some people. Dub, compilers, and IDEs are recurring issues.
Oct 07 2020
next sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Wed, Oct 07, 2020 at 07:15:42PM +0000, aberba via Digitalmars-d-learn wrote:
[...]
 It seems the D ecosystem is not immediately obvious to some people.
 Dub, compilers, and IDEs are recurring issues.
This is stuff that needs to be documented up-front and in-your-face. For example, if we're going to be serious about dub, all code examples on the front page of dlang.org ought to use it. Invocation syntax should be shown right there on the front page. It should permeate all documentation and frequently alluded to. Similarly, if we're serious about code.dlang.org, then it also needs to permeate all code examples on dlang.org throughout. It needs to be treated as first-class citizen. Otherwise, it can only be perceived as this nebulous side thing of unclear relevance that people will tend to ignore. T -- Computerese Irregular Verb Conjugation: I have preferences. You have biases. He/She has prejudices. -- Gene Wirchenko
Oct 07 2020
prev sibling parent reply ddcovery <antoniocabreraperez gmail.com> writes:
On Wednesday, 7 October 2020 at 19:15:42 UTC, aberba wrote:

 It seems the D ecosystem is not immediately obvious to some 
 people. Dub, compilers, and IDEs are recurring issues.
and debbuging (particularly inspection)
Oct 08 2020
parent Alaindevos <devosalain ymail.com> writes:
I found dub.json has very important info,
To name three : importPaths , libs , dependencies.
When these are right you have started for 80%.
Without nagging, when you begin you are however lost in the woods 
and it makes the impression to lose interest completely.
For ease there is : targetName, targetPath, sourcePaths.

What is also quite annoying is links to libraries which are 
unmaintained.
E.g. sql-libraries where no code check-in has been done for 
almost ten years.
Oct 08 2020