2020-11-16 23:55:58 +02:00
|
|
|
import Knex from '../types';
|
|
|
|
import { expectType } from 'tsd';
|
2020-11-20 12:46:08 +02:00
|
|
|
import { clientConfig } from './common';
|
2020-11-16 23:55:58 +02:00
|
|
|
|
|
|
|
const knex = Knex(clientConfig);
|
|
|
|
|
|
|
|
// Use:
|
|
|
|
// import Knex from 'knex'
|
|
|
|
// when "esModuleInterop": true
|
|
|
|
|
2020-11-20 12:46:08 +02:00
|
|
|
// This would be `declare module 'knex'` in runtime code
|
2020-11-16 23:55:58 +02:00
|
|
|
declare module '../types' {
|
|
|
|
interface QueryBuilder {
|
2020-11-20 12:46:08 +02:00
|
|
|
customSelect<TRecord, TResult>(
|
|
|
|
value: number
|
|
|
|
): QueryBuilder<TRecord, TResult>;
|
2020-11-16 23:55:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 12:46:08 +02:00
|
|
|
Knex.QueryBuilder.extend('customSelect', function (value: number) {
|
2020-11-16 23:55:58 +02:00
|
|
|
return this.select(this.client.raw(`${value} as value`));
|
|
|
|
});
|
|
|
|
|
|
|
|
const main = async () => {
|
2020-11-20 12:46:08 +02:00
|
|
|
expectType<number[]>(await knex('users').customSelect<any, number[]>(42));
|
|
|
|
};
|