Skip to content

Commit

Permalink
Added extending docs (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicVonk committed Jul 18, 2023
1 parent ccd0a01 commit 67306e9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .vitepress/config.ts
Expand Up @@ -85,6 +85,10 @@ function getGuideSidebar() {
text: 'Migrations',
link: '/guide/migrations'
},
{
text: 'Extending',
link: '/guide/extending'
}
]
}
function getFaqSidebar() {
Expand Down
44 changes: 44 additions & 0 deletions src/guide/extending.md
@@ -0,0 +1,44 @@
# Extending

To extend knex's builders, we have the following methods

```js
knex.SchemaBuilder.extend("functionName", function() {
console.log('Custom Schema Builder Function');
return this;
});
knex.TableBuilder.extend("functionName", function() {
console.log('Custom Table Builder Function');
return this;
});
knex.ViewBuilder.extend("functionName", function() {
console.log('Custom View Builder Function');
return this;
});
knex.ColumnBuilder.extend("functionName", function() {
console.log('Custom Column Builder Function');
return this;
});
```


To add typescript support you can add the following (.d.ts):
```ts
import "knex";
declare module "knex" {
namespace Knex {
interface SchemaBuilder {
functionName (): Knex.SchemaBuilder;
}
interface TableBuilder {
functionName (): Knex.TableBuilder;
}
interface ViewBuilder {
functionName (): Knex.ViewBuilder;
}
interface ColumnBuilder {
functionName (): Knex.ColumnBuilder;
}
}
}
```

0 comments on commit 67306e9

Please sign in to comment.