tags:

views:

189

answers:

6
+1  Q: 

Adaptive Database

Are there any rapid Database protoyping tools that don't require me to declare a database schema, but rather create it based on the way I'm using my entities.

For example, assuming an empty database (pseudo code):

user1 = new User()  // Creates the user table with a single id column
user1.firstName = "Allain" // alters the table to have a firstName column as varchar(255)

user2 = new User()  // Reuses the table
user2.firstName = "Bob"
user2.lastName = "Loblaw"  // Alters the table to have a last name column

Since there are logical assumptions that can be made when dynamically creating the schema, and you could always override its choices by using your DB tools to tweak it later.

Also, you could generate your schema by unit testing it this way.

And obviously this is only for prototyping.

Is there anything like this out there?

+2  A: 

Google's Application Engine works like this. When you download the toolkit you get a local copy of the database engine for testing.

Eric Z Beard
A: 

May be not exactly responding to your general question, but if you used (N)Hibernate then you can automatically generate the database schema from your hbm mapping files.

Its not done directly from your code as you seem to be wanting but Hibernate Schema generation seems to work well for us

Tom Carter
+1  A: 

Grails uses Hibernate to persist domain objects and produces behavior similar to what you describe. To alter the schema you simply modify the domain, in this simple case the file is named User.groovy.

class User {

    String userName
    String firstName
    String lastName
    Date dateCreated
    Date lastUpdated

    static constraints = {
     userName(blank: false, unique: true)
     firstName(blank: false)
     lastName(blank: false)
    }

    String toString() {"$lastName, $firstName"}

}

Saving the file alters the schema automatically. Likewise, if you are using scaffolding it is updated. The prototype process becomes run the application, view the page in your browser, modify the domain, refresh the browser, and see the changes.

Ed.T
A: 

Do you want the schema, but have it generated, or do you actually want NO schema?

For the former I'd go with nhibernate as @tom-carter said. Have it generate your schema for you, and you are all good (atleast until you roll your app out, then look at something like Tarantino and RedGate SQL Diff or whatever it's called to generate update scripts)

If you want the latter.... google app engine does this, as I've discovered this afternoon, and it's very nice. If you want to stick with code under your control, I'd suggest looking at CouchDB, tho it's a bit of upfront work getting it setup. But once you have it, it's a totally, 100% schema-free database. Well, you have an ID and a Version, but thats it - the rest is up to you. http://incubator.apache.org/couchdb/

But by the sounds of it (N)hibernate would suite the best, but I could be wrong.

Nic Wise
A: 

You could use an object database.

Rik
+1  A: 

I agree with the NHibernate approach and auto-database-generation. But, if you want to avoid writing a configuration file, and stay close to the code, use Castle's ActiveRecord. You declare the 'schema' directly on the class with via attributes.

[ActiveRecord]
public class User : ActiveRecordBase<User>
{
     [PrimaryKey]
     public Int32 UserId { get; set; }

     [Property]
     public String FirstName { get; set; }
}

There are a variety of constraints you can apply (validation, bounds, etc) and you can declare relationships between different data model classes. Most of these options are parameters added to the attributes. It's rather simple.

So, you're working with code. Declaring usage in code. And when you're done, let ActiveRecord create the database.

ActiveRecordStarter.Initialize();
ActiveRecordStarter.CreateSchema();
Anthony Mastrean
Oh and for prototyping, use the in-memory SQLite database engine! (ADO.NET provider here <http://sqlite.phxsoftware.com/>)
Anthony Mastrean