FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ORM status?

 
Post new topic   Reply to topic     Forum Index -> Sendero
View previous topic :: View next topic  
Author Message
dhasenan



Joined: 03 Feb 2005
Posts: 73
Location: New York

PostPosted: Sun Jan 27, 2008 10:41 am    Post subject: ORM status? Reply with quote

Hi --

I'm starting an independent ORM system, and I was curious as to the status of yours, in case we can work together on it. Sendero trunk doesn't have much that's db-related, though the prealpha branch does.

What I'm working on is patterned after NHibernate, with a mixin-based, CSS-style configuration system. From what I can tell, the prealpha branch of Sendero would have a configuration mechanism of:
TableDescriptionOf!(typeof(this)).tablename = "Table1";
TableDescriptionOf!(typeof(this)).columns[0].columnname = "blah";

I am implementing something more like:
mixin(dbfield!(string, "nameOfFieldInClass", "column: blah; notnull: true; length: 200"));

Let me know if you'd like to work together.
Back to top
View user's profile Send private message AIM Address
aaronc542



Joined: 22 May 2007
Posts: 35
Location: NJ, USA

PostPosted: Wed Jan 30, 2008 10:14 am    Post subject: Reply with quote

Hi dhasenan,

Let's talk about it. If possible, it's always best to try to collaborate on these types of projects.

In the pre-alpha version of Sendero there is no configuration because I was using compile-time reflection to inspect the classes.

You can define a class like this:

Code:
class User
{
PrimaryKey id;
char[] username;
char[] email;
}


The pre-Alpha version would then make it easy for you to insert, update, etc. and would create and alter your table definitions using compile-time reflection.

I took this functionality out of the alpha version. Why????? First of all, I thought that the model was too simplistic. It only worked for database tables that fit the above model and all SQL was generated. There was no easy way to work with your own SQL statements.

So back to basics.... I spoke with the DDBI people and they were interested in having some more energy in their project. What D really needs is a standard cross-DB way of creating prepared statements and binding D types to prepared statements. So I took the initial ORM stuff out of Sendero, starting working on prepared statements for DDBI and created a very basic interface in dbi.PreparedStatement and created an implementation for MySql. So I think the first place for us all to collaborate would be DDBI. At the very least we should have prepared statement implementations for Sqlite and PostgreSql. Also, it would be nice to have some more extensive metadata facilities (i.e. inspecting and modifying table definitions) and maybe some basic sql generation (i.e. generating insert or update statements from a list of fields with the appropriate quoting and format for each database), etc. At first I started working independently from DDBI, but really it's better for us all to collaborate... I see DDBI as basically the foundation. It would be nice to make it a robust foundation for whatever ORM we want to create...

Now as far as what's in Sendero now, I've done two things - created a DBProvider class template that uses static methods with thread local storage to provide a database connection for each active thread and to cache connections and prepared statements in a connection pool. Secondly, I've created the Statement class which is a level of abstraction above IPreparedStatement in DDBI. Whereas the IPreparedStatement class provides low-level binding facilities for D-types to database types, Sendero's Statement class use templated variadic argument functions to allow one to execute or fetch data from the database using whatever D-types of class/structs one wants (assuming that the classes and structs have public fields). So one can write:

Code:

auto stmt = db.prepare("SELECT `name`, `dateofbirth` FROM `users` WHERE `id` = ?");
if(!stmt.execute(5)) throw new Exception("Failed to execute statement");
char[] name;
DateTime dateofbirth;
if(stmt.fetch(name, dateofbirth)) {
  //Process result
}


As far as ORM's like in Rails or in Sendero pre-Alpha, I've taken a step back from that at this moment, although I think we should be thinking about it for the future. Having a good prepared statement API in itself I think is a very powerful feature.... So if you would like to help me take the Sendero ORM to that next level (using the foundations from DDBI and the current Statement API), then by all means. If you want like to use DDBI or Sendero+DDBI as a foundation for your ORM, then that would be great too... And of course any contributions you or anyone else wants to make to DDBI would be appreciated by both teams.... (esp. PreparedStatement implementations for PostgreSql and Sqlite).

Let me know your thoughts.

Aaron
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Sendero All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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