Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for wrapIdentifier configuration parameter #51

Merged
merged 1 commit into from Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions components/Sidebar.jsx
Expand Up @@ -31,6 +31,7 @@ export default class Sidebar extends Component {
<li>&nbsp;&nbsp;– <a href="#Installation-fetchAsString">fetchAsString</a></li>
<li>&nbsp;&nbsp;– <a href="#Installation-migrations">migrations</a></li>
<li>&nbsp;&nbsp;– <a href="#Installation-post-process-response">postProcessResponse</a></li>
<li>&nbsp;&nbsp;– <a href="#Installation-wrap-identifier">wrapIdentifier</a></li>
</ul>

<a className="toc_title" href="#Builder">
Expand Down
40 changes: 40 additions & 0 deletions sections/installation.js
Expand Up @@ -347,4 +347,44 @@ export default [
});
`
},
{
type: "heading",
size: "md",
content: "wrapIdentifier",
href: "Installation-wrap-identifier"
},
{
type: "text",
content: [
"Knex supports transforming identifier names automatically to quoted versions for each dialect.",
"For example `'Table.columnName as foo'` for PostgreSQL is converted to \"Table\".\"columnName\" as \"foo\".",
].join(' ')
},
{
type: "text",
content: [
"With `wrapIdentifier` one may override the way how identifiers are transformed.",
"It can be used to override default functionality and for example to help doing `camelCase` -> `snake_case` conversion.",
].join(' ')
},
{
type: "text",
content: [
"Conversion function `wrapIdentifier(value, dialectImpl): string` gets each part of the identifier as a single `value`",
"and the second parameter is the original conversion function from the dialect implementation.",
"For example `knex('table').withSchema('foo').select('table.field as otherName').where('id', 1)` will call",
"`wrapIdentifier` converter for following values `'table'`, `'foo'`, `'table'`, `'field'`, `'otherName'` and `'id'`.",
].join(' ')
},
{
type: "code",
language: "js",
content: `
var knex = require('knex')({
client: 'mysql',
// overly simplified camelCase -> snake_case converter
wrapIdentifier: (value, origImpl) => origImpl(convertToSnakeCase(value))
});
`
},
]