Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[knex#3033] fix: add tests, fix hasColumn
- Loading branch information
Showing
4 changed files
with
286 additions
and
93 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { isArray, isObject, snakeCase, camelCase, mapKeys } from 'lodash'; | ||
|
||
function mapResponseItem(item) { | ||
if (!isObject(item)) { | ||
return item; | ||
} | ||
|
||
return mapKeys(item, (val, key) => { | ||
return camelCase(key); | ||
}); | ||
} | ||
|
||
export function postProcessResponse(response) { | ||
if (isArray(response)) { | ||
return response.map(mapResponseItem); | ||
} else { | ||
return mapResponseItem(response); | ||
} | ||
} | ||
|
||
export function wrapIdentifier(id, origImpl) { | ||
// _.snakeCase removes the leading _ and places _ in front of numbers, | ||
// mangling the temp table names. | ||
if (id.startsWith('_knex_temp_alter')) { | ||
return origImpl(id); | ||
} | ||
|
||
const parts = id.split('.', 2); | ||
const prefix = parts.length === 2 ? parts[0] + '.' : ''; | ||
const toWrap = prefix ? parts[1] : parts[0]; | ||
return origImpl( | ||
prefix + (toWrap.startsWith('_') ? '_' : '') + snakeCase(toWrap) | ||
); | ||
} |
Oops, something went wrong.