mirror of
https://github.com/knex/knex.git
synced 2025-07-06 16:41:22 +00:00
28 lines
691 B
TypeScript
28 lines
691 B
TypeScript
import { knex } from '../types';
|
|
import { expectType } from 'tsd';
|
|
import { clientConfig } from './common';
|
|
|
|
const knexInstance = knex(clientConfig);
|
|
|
|
// Use:
|
|
// import { Knex } from 'knex'
|
|
|
|
// This would be `declare module 'knex'` in runtime code
|
|
declare module '../types' {
|
|
namespace Knex {
|
|
interface QueryBuilder {
|
|
customSelect<TRecord, TResult>(
|
|
value: number
|
|
): Knex.QueryBuilder<TRecord, TResult>;
|
|
}
|
|
}
|
|
}
|
|
|
|
knex.QueryBuilder.extend('customSelect', function (value: number) {
|
|
return this.select(this.client.raw(`${value} as value`));
|
|
});
|
|
|
|
const main = async () => {
|
|
expectType<number[]>(await knexInstance('users').customSelect<any, number[]>(42));
|
|
};
|