www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - database 0.0.8 released

reply Brian <zoujiaqing gmail.com> writes:
dlang database library: Database abstraction layer for D 
programing language, support PostgreSQL / MySQL / SQLite.

Project:
https://github.com/huntlabs/database


Database abstraction layer for D programing language, support 
PostgreSQL / MySQL / SQLite.


```D

import std.stdio;
import std.experimental.logger;

import database;

void main()
{
     writeln("run database MySQL demo.");

     auto db = new 
Database("mysql://root:123456 localhost:3306/test?charset=utf-8");

     int result = db.execute(`INSERT INTO user(username) 
VALUES("test")`);
     writeln(result);

     foreach(row; db.query("SELECT * FROM user LIMIT 10"))
     {
         writeln(row["username"]);
     }

     db.close();
}

```


```D
auto options = new 
DatabaseOption("mysql://root:123456 localhost:3306/test");
options.setMaximumConnection(5);

auto db = new Database(options);

db.execute("SET NAMES utf8");
```



-  int Database.execute(string sql)  Return number of execute 
result.
```D
     int result = db.execute('INSERT INTO user(username) 
VALUES("Brian")');
     // if execute error ,db will throw an DatabaseException
```
-  ResultSet Database.query(sql) Return ResultSet object for 
query(SELECT).
```D
     ResultSet rs = db.query("SELECT * FROM user LIMIT 10");
```
-  Statement Database.prepare(sql) Create a prepared Statement 
object.
```D
    Statement stmt = db.prepare("SELECT * FROM user where username 
= :username and age = :age LIMIT 10");
```
- Statement.setParameter(param, value) : bind param's value to 
:param for sql.
```D
    stmt.setParameter("username", "viile");
    stmt.setParameter("age", 18);
```
- ResultSet Statement.query()  Return ResultSet
```D
     ResultSet rs = stmt.query();
     foreach(row; rs)
     {
         writeln(row["username"]);
     }
```
- Row Statement.fetch()  Return Row
```D
     Row row = stmt.fetch();
     writeln(row["username"]);
```
- int Statement.execute() : return execute status for prepared 
Statement object.
```D
     int result = stmt.execute();
```
- Statement.lastInsertId() : Statement.execute() for insert sql, 
return lastInsertId.
Sep 12 2017
next sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Tuesday, 12 September 2017 at 17:14:27 UTC, Brian wrote:
 dlang database library: Database abstraction layer for D 
 programing language, support PostgreSQL / MySQL / SQLite.
not bad.
 -  Statement Database.prepare(sql) Create a prepared Statement
ooh, this is something I have been wanting to write for my database libs too...
Sep 12 2017
parent reply Brian <zoujiaqing gmail.com> writes:
On Tuesday, 12 September 2017 at 17:37:23 UTC, Adam D. Ruppe 
wrote:
 On Tuesday, 12 September 2017 at 17:14:27 UTC, Brian wrote:
 dlang database library: Database abstraction layer for D 
 programing language, support PostgreSQL / MySQL / SQLite.
not bad.
 -  Statement Database.prepare(sql) Create a prepared Statement
ooh, this is something I have been wanting to write for my database libs too...
Welcome to participate! :)
Sep 12 2017
parent Adam D. Ruppe <destructionator gmail.com> writes:
On Wednesday, 13 September 2017 at 06:46:59 UTC, Brian wrote:
 Welcome to participate! :)
Alas, looking at your source, it is actually not what I wanted... I want to use the database features rather than a reimplemented class. BTW the "escapedVariants" function can help you fill in that Statement class' missing methods.
Sep 13 2017
prev sibling next sibling parent reply Vadim Lopatin <coolreader.org gmail.com> writes:
On Tuesday, 12 September 2017 at 17:14:27 UTC, Brian wrote:
 dlang database library: Database abstraction layer for D 
 programing language, support PostgreSQL / MySQL / SQLite.

 Project:
 https://github.com/huntlabs/database
Did you see DDBC project? It supports postgres, mysql, and sqlite, too. API is similar to Java JDBC.
Sep 12 2017
parent Brian <zoujiaqing gmail.com> writes:
On Wednesday, 13 September 2017 at 04:30:24 UTC, Vadim Lopatin 
wrote:
 On Tuesday, 12 September 2017 at 17:14:27 UTC, Brian wrote:
 dlang database library: Database abstraction layer for D 
 programing language, support PostgreSQL / MySQL / SQLite.

 Project:
 https://github.com/huntlabs/database
Did you see DDBC project? It supports postgres, mysql, and sqlite, too. API is similar to Java JDBC.
Yes, thanks your project DDBC :) database is similar to PHP PDO library, no deps, api easy to use.
Sep 12 2017
prev sibling next sibling parent rikki cattermole <rikki cattermole.co.nz> writes:
Add on allocator support and many more comments, aka if public facing 
then document it. Then we'd be in business!
Sep 12 2017
prev sibling parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 9/12/17 1:14 PM, Brian wrote:
 dlang database library: Database abstraction layer for D programing 
 language, support PostgreSQL / MySQL / SQLite.
 
 Project:
 https://github.com/huntlabs/database
 

 Database abstraction layer for D programing language, support PostgreSQL 
 / MySQL / SQLite.
I just wanted to point out that in order to bind against libmysqlclient, you must use an open-source license, or pay Oracle a license fee. This means the users of your library must use an open source license or pay the fee (not you), but your license makes it unclear that this is the case. More details here: https://www.mysql.com/about/legal/licensing/foss-exception/ Or you could instead use the mysql-native library that does not depend on Oracle's library: https://github.com/mysql-d/mysql-native -Steve
Sep 13 2017