Created
May 21, 2017 15:29
-
-
Save koistya/72bb734a0ad617f692b259d72d8ad011 to your computer and use it in GitHub Desktop.
“camelCase” < = > “snake_case” conversion with PostgreSQL and Knex.js https://medium.com/p/956357872fe4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import db from './db'; | |
const fields = ['id', 'email', 'is_admin as isAdmin']; | |
class User { | |
constructor(data) { | |
Object.assign(this, data); | |
} | |
static find(...where) { | |
return db.table('users') | |
.where(...where) | |
.select(...fields) | |
.then(rows => rows.map(row => new User(row)); | |
} | |
} | |
export default User; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment