Skip to content

Commit

Permalink
Merge pull request #2 from taghash/Extending_RaW_Feature
Browse files Browse the repository at this point in the history
extending raw feature
  • Loading branch information
shrikrishnaholla authored Oct 27, 2023
2 parents 82f43d5 + 8204adc commit 03bd26d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/knex-builder/Knex.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ knex.SchemaBuilder = {
},
};

Knex.Raw = {
extend: function (methodName, fn) {
Raw.extend(methodName, fn);
},
};

knex.ViewBuilder = {
extend: function (methodName, fn) {
ViewBuilder.extend(methodName, fn);
Expand Down
11 changes: 11 additions & 0 deletions lib/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ class Raw extends EventEmitter {
// Workaround to avoid circular dependency between wrappingFormatter.unwrapRaw and rawFormatter
Raw.prototype.isRawInstance = true;

//Extending raw feature
Raw.extend = (methodName, fn) => {
if (Object.prototype.hasOwnProperty.call(Raw.prototype, methodName)) {
throw new Error(
`Can't extend Raw with existing method ('${methodName}').`
);
}

assign(Raw.prototype, {[methodName]: fn});
};

// Allow the `Raw` object to be utilized with full access to the relevant
// promise API.
augmentWithBuilderInterface(Raw);
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"extends": "@tsconfig/node12/tsconfig.json",
"compilerOptions": {
"strict": true,
"esModuleInterop": true,
Expand Down

0 comments on commit 03bd26d

Please sign in to comment.