eDBI is born, feedback wanted
- Posted by jeremy (admin) Aug 27, 2009
- 2372 views
eDBI is born. Please see eDBI for more information. A quick run down here, though:
- Allows a common API to many different database servers/clients.
- Database drivers are loaded dynamically, allowing your application to work with database drivers you've never even seen before.
- Database drivers are easily written and do not require any changes to eDBI or your application to make them work.
- eDBI works with Euphoria types, for instance, when you perform a query that contains a varchar, integer, decimal and a date/time value, you will not get back all "string" sequences. You will get back a sequence, an integer, an atom and a datetime (from std/datetime.e). Further, when doing queries, you can use these types directly as well.
An example:
-- -- Example edbi use -- include std/datetime.e include edbi/edbi.e sequence data = { { "Ronald Mc'Donald", 29382, datetime:subtract(datetime:new(), 32, YEARS) }, { "Super Man", 55555, datetime:new(1944, 5, 18) }, { "Wonder Woman", 21232, datetime:new(1972, 9, 29) } } edbi:set_driver_path("drivers") edbi:db_handle dbh = edbi:open("sqlite3://example.db") edbi:execute("DROP TABLE people") edbi:execute("CREATE TABLE people (name VARCHAR(30), zip INTEGER, dob datetime)") for i = 1 to length(data) do edbi:execute("INSERT INTO people VALUES (%s, %d, %D)", data[i]) end for edbi:dbr_handle dbr = edbi:query("SELECT * FROM people") object person while sequence(person) with entry do printf(1, "Name=%s, Zip=%d, Dob=%s\n", { person[1], person[2], datetime:format(person[3], "%m/%d/%Y") }) entry person = edbi:next(dbr) end while edbi:close()
Now, to make that work, on say, MySQL, just change the opening line to:
edbi:db_handle dbh = edbi:open("mysql://localhost?dbname=people")
The same is true for any database driver that may exist.
What database drivers exist right now? Just the reference implementation, SQLite3. I am looking for help on other ones. The next highest priority is MySQL then PgSQL.
If you are interested in joining in on this project, please let me know.
Jeremy