1602 / jugglingdb

Multi-database ORM for nodejs: redis, mongodb, mysql, sqlite3, postgresql, arango, in-memory...
http://1602.github.io/jugglingdb/
2.04k stars 241 forks source link

Support separate field names used for storage. #312

Closed alexmingoia closed 10 years ago

alexmingoia commented 11 years ago

This closes #119 by adding support for storing data using a field name defined by the schema.

For example, to store emailAddress as email_address, you use the name parameter:

var User = schema.define('User', {
  name: String,
  emailAddress: { type: String, name: 'email_address' }
});

I've added a test for it and updated documentation: https://github.com/alexmingoia/jugglingdb/blob/custom-fieldnames/docs/schema.md#custom-database-columnfield-names

lwansbrough commented 11 years ago

Thanks for this.

yanickrochon commented 10 years ago

How are the field names normally generated? If JugglingDB'd make usage of Underscore.String, it could make use of the _s.underscored("emailAddress") == "email_address" function.

I'd see this feature to override the default behaviour when using "weird" schemas, or normalizing models.

My 2 cents.

qfox commented 10 years ago

I think it's have buggy behaviour on create/update databases.

qfox commented 10 years ago

Just look at this: https://gist.github.com/zxqfox/19662d3ec545a149924c testing with postgres adapter. Guys. How to write tests for adapters? What should be placed in jugglingdb? Atm I didn't see any tests in jugglingdb/postgres adapter