mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-09 11:40:07 +00:00
74
types/cassanknex/cassanknex-tests.ts
Normal file
74
types/cassanknex/cassanknex-tests.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import cassanknex = require('cassanknex');
|
||||
|
||||
const knex = cassanknex({
|
||||
connection: {
|
||||
contactPoints: ['127.0.0.1']
|
||||
}
|
||||
});
|
||||
|
||||
knex.on('ready', (err) => {
|
||||
});
|
||||
|
||||
interface BirdRow {
|
||||
type: string;
|
||||
canFly: boolean;
|
||||
}
|
||||
|
||||
const qb = knex("animals")
|
||||
.insert<BirdRow>({
|
||||
type: 'Stork',
|
||||
canFly: true
|
||||
})
|
||||
.into('birds');
|
||||
|
||||
qb.exec((err, res) => {
|
||||
});
|
||||
|
||||
qb.eachRow((n, row) => {
|
||||
}, (err) => {
|
||||
});
|
||||
|
||||
interface FooRow {
|
||||
id: string;
|
||||
foo: string;
|
||||
bar: number;
|
||||
baz: string[];
|
||||
}
|
||||
|
||||
const query2 = knex("keyspace")
|
||||
.select<FooRow>("id", "foo", "bar", "baz")
|
||||
.ttl('foo')
|
||||
.where("id", "=", "1")
|
||||
.orWhere("id", "in", ["2", "3"])
|
||||
.orWhere("baz", "=", ["bar"])
|
||||
.andWhere("foo", "IN", ["baz", "bar"])
|
||||
.limit(10)
|
||||
.from("table");
|
||||
|
||||
query2.stream({
|
||||
readable() {
|
||||
const row = this.read();
|
||||
},
|
||||
end() {},
|
||||
error() {}
|
||||
});
|
||||
|
||||
const values = {
|
||||
id: "foo",
|
||||
bar: 13,
|
||||
baz: ["foo", "bar"]
|
||||
};
|
||||
|
||||
const query3 = knex("cassanKnexy")
|
||||
.insert<FooRow>(values)
|
||||
.usingTimestamp(250000)
|
||||
.usingTTL(50000)
|
||||
.into("columnFamily");
|
||||
|
||||
const [cql, params] = [query3.cql(), query3.bindings()];
|
||||
|
||||
const query4 = knex("cassanKnexy")
|
||||
.update("columnFamily")
|
||||
.add("bar", { foo: "baz" }) // "bar" is a map
|
||||
.remove("foo", ["bar"]) // "foo" is a set
|
||||
.where("id", "=", 1);
|
||||
204
types/cassanknex/index.d.ts
vendored
Normal file
204
types/cassanknex/index.d.ts
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
// Type definitions for cassanknex 1.19
|
||||
// Project: https://github.com/azuqua/cassanknex
|
||||
// Definitions by: Daniel Chao <https://github.com/bioball>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import { EventEmitter } from "events";
|
||||
import { Client, ClientOptions, types, ResultCallback } from "cassandra-driver";
|
||||
import * as Long from "long";
|
||||
import { Readable } from "stream";
|
||||
|
||||
declare function CassanKnex(options?: CassanKnex.DriverOptions): CassanKnex.CassanKnex;
|
||||
|
||||
export = CassanKnex;
|
||||
|
||||
declare namespace CassanKnex {
|
||||
interface DriverOptions {
|
||||
debug?: boolean;
|
||||
connection?: Client | ClientOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will return the `never` type if `T[K]` is not a member of `Type`, for all `T[K]`.
|
||||
*/
|
||||
type TypeMatchedValue<T, K extends keyof T, Type, This> = T[K] extends Type ? This : never;
|
||||
|
||||
interface MappedDict<B> {
|
||||
[key: string]: B;
|
||||
}
|
||||
|
||||
type InRestriction = 'in' | 'IN';
|
||||
|
||||
type ComparisonRestriction = '=' | '<' | '>' | '<=' | '>=';
|
||||
|
||||
type SelectAsClause<T> = {
|
||||
[P in keyof T]: string;
|
||||
};
|
||||
|
||||
interface CassanKnex extends EventEmitter {
|
||||
(keyspace?: string): QueryBuilderRoot;
|
||||
}
|
||||
|
||||
interface StreamParams {
|
||||
readable: (this: Readable) => any;
|
||||
end: (this: Readable) => any;
|
||||
error: (err: Error) => any;
|
||||
}
|
||||
|
||||
interface QueryBuilderRoot {
|
||||
insert <T = any>(values: Partial<T> | T): InsertQueryBuilder;
|
||||
select <T = any>(...columns: Array<keyof T>): SelectQueryBuilder<T>;
|
||||
select <T = any>(values: SelectAsClause<T>): SelectQueryBuilder<T>;
|
||||
update <T = any>(table: string): UpdateQueryBuilder<T>;
|
||||
delete <T = any>(): DeleteQueryBuilder<T>;
|
||||
alterColumnFamily <T = any>(columnFamily: string): AlterColumnFamilyQueryBuilder<T>;
|
||||
createColumnFamily <T = any>(columnFamily: string): CreateColumnFamilyQueryBuilder<T>;
|
||||
createColumnFamilyIfNotExists <T = any>(columnFamily: string): CreateColumnFamilyQueryBuilder<T>;
|
||||
createIndex <T = any>(columnFamily: string, indexName: string, column: keyof T): QueryBuilder;
|
||||
createIndexCustom <T = any>(columnFamily: string, indexName: string, column: keyof T): QueryBuilder & CreateableIndexBuilder;
|
||||
createType <T = any>(typeName: string): CreateTypeQueryBuilder<T>;
|
||||
createTypeIfNotExists <T = any>(typeName: string): CreateTypeQueryBuilder<T>;
|
||||
dropColumnFamily(columnFamily: string): QueryBuilder;
|
||||
dropColumnFamilyIfExists(columnFamily: string): QueryBuilder;
|
||||
dropType(): QueryBuilder;
|
||||
dropTypeIfExists(): QueryBuilder;
|
||||
truncate(columnFamily: string): QueryBuilder;
|
||||
alterKeyspace(keyspace: string): KeyspaceQueryBuilder;
|
||||
createKeyspace(keyspace: string): KeyspaceQueryBuilder;
|
||||
createKeyspaceIfNotExists(keyspace: string): KeyspaceQueryBuilder;
|
||||
dropKeyspace(): QueryBuilder;
|
||||
dropKeyspaceIfExists(): QueryBuilder;
|
||||
}
|
||||
|
||||
interface QueryBuilder {
|
||||
cql(): string;
|
||||
bindings(): any[];
|
||||
exec(cb: ResultCallback): undefined;
|
||||
eachRow(onEachRow: (n: number, row: types.Row) => any, onError: (err: Error) => any): undefined;
|
||||
stream(params: StreamParams): undefined;
|
||||
}
|
||||
|
||||
interface FieldValueQueryBuilder<T> {
|
||||
decimal <K extends keyof T>(columnName: K): TypeMatchedValue<T, K, types.BigDecimal, this>;
|
||||
boolean <K extends keyof T>(columnName: K): TypeMatchedValue<T, K, boolean, this>;
|
||||
blob <K extends keyof T>(columnName: K): TypeMatchedValue<T, K, Buffer, this>;
|
||||
timestamp <K extends keyof T>(columnName: K): TypeMatchedValue<T, K, Date, this>;
|
||||
date <K extends keyof T>(columnName: K): TypeMatchedValue<T, K, types.LocalDate, this>;
|
||||
inet <K extends keyof T>(columnName: K): TypeMatchedValue<T, K, types.InetAddress, this>;
|
||||
bigint <K extends keyof T>(columnName: K): TypeMatchedValue<T, K, Long, this>;
|
||||
counter <K extends keyof T>(columnName: K): TypeMatchedValue<T, K, Long, this>;
|
||||
double <K extends keyof T>(columnName: K): TypeMatchedValue<T, K, Long, this>;
|
||||
int <K extends keyof T>(columnName: K): TypeMatchedValue<T, K, number, this>;
|
||||
float <K extends keyof T>(columnName: K): TypeMatchedValue<T, K, number, this>;
|
||||
map <K extends keyof T, A extends string, B>(columnName: K, a: A, b: B): TypeMatchedValue<T, K, Map<A, B>, this>;
|
||||
ascii <K extends keyof T>(columnName: K): TypeMatchedValue<T, K, string, this>;
|
||||
text <K extends keyof T>(columnName: K): TypeMatchedValue<T, K, string, this>;
|
||||
timeuuid <K extends keyof T>(columnName: K): TypeMatchedValue<T, K, types.TimeUuid, this>;
|
||||
uuid <K extends keyof T>(columnName: K): TypeMatchedValue<T, K, types.Uuid, this>;
|
||||
varchar <K extends keyof T>(columnName: K): TypeMatchedValue<T, K, string, this>;
|
||||
list <K extends keyof T>(columnName: K, typeName: string): TypeMatchedValue<T, K, any[], this>;
|
||||
primary(primaryKey: string): this;
|
||||
set <K extends keyof T, A extends string>(columnName: K, a: A): TypeMatchedValue<T, K, Set<T[K]>, this>;
|
||||
}
|
||||
|
||||
interface CreateableColumnFamilyBuilder<T> {
|
||||
withCaching(): this;
|
||||
withCompression(): this;
|
||||
withCompaction(): this;
|
||||
withClusteringOrderBy <K extends keyof T>(value: K, direction: 'desc' | 'asc'): this;
|
||||
}
|
||||
|
||||
interface CreateableIndexBuilder {
|
||||
withOptions(opts: MappedDict<string>): this;
|
||||
}
|
||||
|
||||
interface KeyspaceableQueryBuilder {
|
||||
withNetworkTopologyStrategy(strategy: MappedDict<number>): this;
|
||||
withSimpleStrategy(replicas: number): this;
|
||||
withDurableWrites(durableWrites: boolean): this;
|
||||
}
|
||||
|
||||
interface InsertableQueryBuilder {
|
||||
into(table: string): this;
|
||||
ifNotExists(): this;
|
||||
}
|
||||
|
||||
interface TtlableQueryBuilder {
|
||||
usingTimestamp(timestamp: number): this;
|
||||
usingTTL(ttl: number): this;
|
||||
}
|
||||
|
||||
interface WhereableQueryBuilder<T> {
|
||||
where <K extends keyof T>(lhs: K, comparison: InRestriction, rhs: Array<T[K]>): this;
|
||||
where <K extends keyof T>(lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this;
|
||||
orWhere <K extends keyof T>(lhs: K, comparison: InRestriction, rhs: Array<T[K]>): this;
|
||||
orWhere <K extends keyof T>(lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this;
|
||||
andWhere <K extends keyof T>(lhs: K, comparison: InRestriction, rhs: Array<T[K]>): this;
|
||||
andWhere <K extends keyof T>(lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this;
|
||||
tokenWhere <K extends keyof T>(lhs: K, comparison: InRestriction, rhs: Array<T[K]>): this;
|
||||
tokenWhere <K extends keyof T>(lhs: K, comparison: ComparisonRestriction, rhs: T[K]): this;
|
||||
ttl <K extends keyof T>(columnName: K): this;
|
||||
}
|
||||
|
||||
interface IfableQueryBuilder<T> {
|
||||
if <K extends keyof T>(lhs: K, comparison: ComparisonRestriction, rhs: T[K] | null): this;
|
||||
}
|
||||
|
||||
interface LimitableQueryBuilder {
|
||||
limit(limit: number): this;
|
||||
limitPerPartition(limit: number): this;
|
||||
}
|
||||
|
||||
interface FromableQueryBuilder {
|
||||
from(table: string): this;
|
||||
}
|
||||
|
||||
interface UpdateableQueryBuilder<T> {
|
||||
set <K extends keyof T>(key: K, value: T[K]): this;
|
||||
set(object: Partial<T>): this;
|
||||
add <K extends keyof T>(key: K, value: { [str: string]: T[K] }): TypeMatchedValue<T, K, Map<string, T[K]>, this>;
|
||||
add <K extends keyof T>(key: K, value: Array<T[K]>): TypeMatchedValue<T, K, any[] | Set<any>, this>;
|
||||
add(object: Partial<T>): this;
|
||||
remove <K extends keyof T>(key: K, value: Array<T[K]>): this;
|
||||
remove(object: Partial<T>): this;
|
||||
increment(column: keyof T, amount: number): this;
|
||||
increment(object: Partial<T>): this;
|
||||
decrement(column: keyof T, amount: number): this;
|
||||
decrement(object: Partial<T>): this;
|
||||
}
|
||||
|
||||
interface AlterableQueryBuilder<T> {
|
||||
drop <K extends keyof T>(...columns: K[]): this;
|
||||
rename <K extends keyof T>(column: K, newColumn: K): this;
|
||||
alter <K extends keyof T>(column: K, newType: string): this;
|
||||
}
|
||||
|
||||
type InsertQueryBuilder = QueryBuilder
|
||||
& InsertableQueryBuilder
|
||||
& TtlableQueryBuilder;
|
||||
type SelectQueryBuilder<T> = QueryBuilder
|
||||
& WhereableQueryBuilder<T>
|
||||
& LimitableQueryBuilder
|
||||
& FromableQueryBuilder;
|
||||
type UpdateQueryBuilder<T> = QueryBuilder
|
||||
& WhereableQueryBuilder<T>
|
||||
& UpdateableQueryBuilder<T>
|
||||
& IfableQueryBuilder<T>
|
||||
& TtlableQueryBuilder;
|
||||
type DeleteQueryBuilder<T> = QueryBuilder
|
||||
& WhereableQueryBuilder<T>
|
||||
& FromableQueryBuilder;
|
||||
type CreateColumnFamilyQueryBuilder<T> = QueryBuilder
|
||||
& FieldValueQueryBuilder<T>
|
||||
& CreateableColumnFamilyBuilder<T>;
|
||||
type KeyspaceQueryBuilder = QueryBuilder
|
||||
& KeyspaceableQueryBuilder;
|
||||
type CreateTypeQueryBuilder<T> = QueryBuilder
|
||||
& FieldValueQueryBuilder<T>;
|
||||
type AlterColumnFamilyQueryBuilder<T> = QueryBuilder
|
||||
& AlterableQueryBuilder<T>
|
||||
& FieldValueQueryBuilder<T>;
|
||||
}
|
||||
24
types/cassanknex/tsconfig.json
Normal file
24
types/cassanknex/tsconfig.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"cassanknex-tests.ts"
|
||||
]
|
||||
}
|
||||
7
types/cassanknex/tslint.json
Normal file
7
types/cassanknex/tslint.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false,
|
||||
"strict-export-declare-modifiers": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user