View previous topic :: View next topic |
Author |
Message |
jeremy_c
Joined: 09 Apr 2005 Posts: 16 Location: Ohio, USA
|
Posted: Tue Apr 26, 2005 8:24 am Post subject: Welcome to DDBI! |
|
|
First, I want to thank DSource.org for hosting these services.
Second, I want to introduce D DBI. D DBI is a database independent interface for the D programming language. What this means is a common interface to many types of database backends.
For instance:
Code: | import dbi.sqlite.SqliteDatabase;
//import dbi.pg.PgDatabase;
//import dbi.mysql.MysqlDatabase;
void main() {
// PgDatabase db = new PgDatabase();
// MysqlDatabase db = new MysqlDatabase();
// db.connect("dbname=test");
SqliteDatabase db = new SqliteDatabase();
db.connect("_test.db");
Row[] rows = db.queryFetchAll("SELECT * FROM names");
for (Row row; rows) {
printf("name: ?.*s zip: ?.*s\n", row["name"], row["zip"]);
}
db.close();
} |
That program will work on all database systems that D DBI currently supports without change, except the connect statement. As you can see, at the time of this post, D DBI supports SQLite v3, MySQL and PostgreSQL.
It is my hopes that the community will begin discussion of D DBI and through a community effort shape D DBI into a full featured DBI system for the D programming language. Others have already contributed to the code, such as the SQLite3 C wrapper and the MySQL C wrapper.
D DBI's home page is currently http://jeremy.cowgar.com/ddbi/ but will soon be changing to ddbi.dsource.org (thanks again to dsource.org). Downloads are currently available there.
Feel free to start the discussion! The API needs some work, more database drivers need to be added, better documentation and example programs needs to be created however, in it's current state, it is very usable. So, let the discussion and use begin!
Jeremy Cowgar
http://jeremy.cowgar.com
[/code]
Last edited by jeremy_c on Tue Apr 26, 2005 1:08 pm; edited 1 time in total |
|
Back to top |
|
|
pragma
Joined: 28 May 2004 Posts: 607 Location: Washington, DC
|
Posted: Tue Apr 26, 2005 9:38 am Post subject: |
|
|
Welcome to dsource!
I've been over your API multiple times, and I think I found some things that would be very nice to have.
1) escape sequences. Different database vendors have slightly different conventions on how to deal with embeded single-quotes and the like. I see a reference to an 'escape' function in your doc index, but shouldn't this be tied to the various db implementation classes instead?
Code: |
db.queryFetchAll("select * from mytable where x = '" ~ db.escape(mystr) ~ "'");
|
Also, a writef-like version of this that automatically escapes would be even better:
Code: |
db.queryFetchAll("select * from mytable where x='{0}' and y='{1}'",mystr,mystr2);
|
2) It would be nice to have a 'query' object that can be resued in places, instead of having to wield SQL all the time.
Code: |
Query q = db.createQuery("select * from mytable where x='{0}' and y='{1}'");
Reqsult r = q.fetchAll(mystr,mystr2);
|
(createQuery could self-optimize by breaking down the string into text and subtitution parts... so parsing overhead can be eliminated later on)
IMO, This would help in further side-stepping the differences between database vendors as no two SQL implementations are alike. _________________ -- !Eric.t.Anderton at gmail |
|
Back to top |
|
|
jeremy_c
Joined: 09 Apr 2005 Posts: 16 Location: Ohio, USA
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|