<p>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.</p>

<p>For example, assuming an empty database (pseudo code):</p>

<pre><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
</code></pre>

<p>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.</p>

<p>Also, you could generate your schema by unit testing it this way.</p>

<p>And obviously this is only for prototyping.</p>

<p>Is there anything like this out there?</p>

[{'answer_id': 32297, 'author': 'Eric Z Beard', 'author_id': 1219, 'author_profile': 'https://Stackoverflow.com/users/1219', 'pm_score': 3, 'selected': True, 'text': '<p><a href="http://code.google.com/appengine/" rel="nofollow noreferrer">Google\'s Application Engine</a> works like this.  When you download the toolkit you get a local copy of the database engine for testing.</p>\n'}, {'answer_id': 32301, 'author': 'Tom Carter', 'author_id': 2839, 'author_profile': 'https://Stackoverflow.com/users/2839', 'pm_score': 0, 'selected': False, 'text': '<p>May be not exactly responding to your <em>general</em> question, but if you used <a href="http://www.hibernate.org" rel="nofollow noreferrer">(N)Hibernate</a> then you can automatically generate the database schema from your hbm mapping files.</p>\n\n<p>Its not done directly from your code as you seem to be wanting but Hibernate Schema generation seems to work well for us </p>\n'}, {'answer_id': 32463, 'author': 'Ed.T', 'author_id': 3014, 'author_profile': 'https://Stackoverflow.com/users/3014', 'pm_score': 1, 'selected': False, 'text': '<p>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.</p>\n\n<pre><code>class User {\n\n    String userName\n    String firstName\n    String lastName\n    Date dateCreated\n    Date lastUpdated\n\n    static constraints = {\n        userName(blank: false, unique: true)\n        firstName(blank: false)\n        lastName(blank: false)\n    }\n\n    String toString() {"$lastName, $firstName"}\n\n}\n</code></pre>\n\n<p>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.</p>\n'}, {'answer_id': 36312, 'author': 'Nic Wise', 'author_id': 2947, 'author_profile': 'https://Stackoverflow.com/users/2947', 'pm_score': 0, 'selected': False, 'text': '<p>Do you want the schema, but have it generated, or do you actually want <strong>NO schema</strong>?</p>\n\n<p>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)</p>\n\n<p>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. <a href="http://incubator.apache.org/couchdb/" rel="nofollow noreferrer">http://incubator.apache.org/couchdb/</a></p>\n\n<p>But by the sounds of it (N)hibernate would suite the best, but I could be wrong.</p>\n'}, {'answer_id': 52055, 'author': 'Rik', 'author_id': 5409, 'author_profile': 'https://Stackoverflow.com/users/5409', 'pm_score': 0, 'selected': False, 'text': '<p>You could use an object database. </p>\n'}, {'answer_id': 52086, 'author': 'Anthony Mastrean', 'author_id': 3619, 'author_profile': 'https://Stackoverflow.com/users/3619', 'pm_score': 1, 'selected': False, 'text': '<p>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 <a href="http://www.castleproject.org/activerecord/index.html" rel="nofollow noreferrer">ActiveRecord</a>. You declare the \'schema\' directly on the class with via attributes.</p>\n\n<pre><code>[ActiveRecord]\npublic class User : ActiveRecordBase&lt;User&gt;\n{\n     [PrimaryKey]\n     public Int32 UserId { get; set; }\n\n     [Property]\n     public String FirstName { get; set; }\n}\n</code></pre>\n\n<p>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.</p>\n\n<p>So, you\'re working with code. Declaring usage in code. And when you\'re done, let ActiveRecord <a href="http://www.castleproject.org/activerecord/documentation/trunk/usersguide/schemagen.html" rel="nofollow noreferrer">create the database</a>.</p>\n\n<pre><code>ActiveRecordStarter.Initialize();\nActiveRecordStarter.CreateSchema();\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/32231', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2443/']