-
Notifications
You must be signed in to change notification settings - Fork 18
Creating a new Adapter
Zach Silveira edited this page Nov 10, 2016
·
1 revision
This is a short guide on creating a new adapter.
###Initial setup
After cloning the repo, make a new folder inside modules/orm/adapters
with the name of your adapter. For this example, we will act like we are making a postgres adapter.
Edit modules/orm/adapters/index.js
import mysql from './mysql'
import postgres from './postgres' //your new adapter
const adapters = {
mysql,
postgres, //your new adapter
}
/*
Loads an adapter based on DB_DRIVER env
*/
export default adapters[process.env.DB_DRIVER]
Now, create an index.js file in your new folder (modules/orm/adapters/postgres/index
)
This is your main adapter. You can see the mysql one for reference. It should have the following methods at a minimum
import connection from './connection'
import Builder from './builder'
import { getTableName } from '../../../global/get-name'
class PostgresAdapter {
/*
Generic Adapter Methods (these should be in every adapter)
select, create, queryBuilder, getJoins, makeRelatable
/*
select({ model, select, where, limit, joins = [] }) {
}
create({ model, data }) {
}
queryBuilder(options) {
}
getJoins(joins) {
}
makeRelatable(result, model) {
}
}
export default new MysqlAdapter()
There's more to it, but you can figure it out from the existing adapters. Simply change your DB_DRIVER env to the new adapter to test.