Skip to content

Commit f8e238c

Browse files
committed
Merge pull request #369 from nerdzeu/master
Fix and improve TypeScript declaration
2 parents 8247857 + 145ba51 commit f8e238c

File tree

2 files changed

+96
-66
lines changed

2 files changed

+96
-66
lines changed

lib/TypeScript/orm.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare module "orm" {
44

55
import events = require('events');
6+
import sqlquery = require('sqlquery');
67

78
module orm {
89

@@ -26,6 +27,7 @@ declare module "orm" {
2627
order?: any;
2728
}, callback: (err: Error, results: Instance[]) => void): Model;
2829
find(conditions: { [property: string]: any }, limit: number, order: string[], callback: (err: Error, results: Instance[]) => void): Model;
30+
find(conditions: { [property: string]: any }): IChainFind;
2931

3032
all(conditions: { [property: string]: any }, callback: (err: Error, results: Instance[]) => void): Model;
3133
all(conditions: { [property: string]: any }, options: {
@@ -123,6 +125,22 @@ declare module "orm" {
123125
get(callback: (err: Error, instance: Instance) => void);
124126
}
125127

128+
export interface IChainFind {
129+
find(conditions: { [property: string]: any }): IChainFind;
130+
only(...args: string[]): IChainFind;
131+
limit(limit: number): IChainFind;
132+
offset(offset: number): IChainFind;
133+
run(callback: (err: Error, results: Instance[]) => void): void;
134+
count(callback: (err: Error, count: number) => void): void;
135+
remove(callback: (err: Error) => void): void;
136+
save(callback: (err: Error) => void): void;
137+
each(callback: (result: Instance) => void): void;
138+
each(): IChainFind;
139+
filter(callback: (result: Instance) => boolean): IChainFind;
140+
sort(callback: (a: Instance, b: Instance) => boolean): IChainFind;
141+
get(callback: (results: Instance[]) => void): IChainFind;
142+
}
143+
126144
/*
127145
* Classes
128146
*/
@@ -234,6 +252,15 @@ declare module "orm" {
234252
}
235253

236254
export function Text(type: string): sqlquery.TextQuery;
255+
export function eq(value: any): sqlquery.Comparator;
256+
export function ne(value: any): sqlquery.Comparator;
257+
export function gt(value: any): sqlquery.Comparator;
258+
export function gte(value: any): sqlquery.Comparator;
259+
export function lt(value: any): sqlquery.Comparator;
260+
export function lte(value: any): sqlquery.Comparator;
261+
export function like(value: string): sqlquery.Comparator;
262+
export function between(a: number, b: number): sqlquery.Comparator;
263+
export function not_between(a: number, b: number): sqlquery.Comparator;
237264
export function express(uri: string, handlers: {
238265
define(db: ORM, models: { [key: string]: Model });
239266
}): (req, res, next) => void;

lib/TypeScript/sql-query.d.ts

Lines changed: 69 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,79 @@
1-
declare module sqlquery {
2-
export class Query {
3-
constructor(dialect: string);
4-
constructor(options: {
5-
dialect: string;
6-
});
7-
static Text(type: string): TextQuery;
1+
declare module "sqlquery" {
2+
module sqlquery {
3+
export class Query {
4+
constructor(dialect: string);
5+
constructor(options: {
6+
dialect: string;
7+
});
8+
static Text(type: string): TextQuery;
89

9-
static Comparators: string[];
10-
static between(a: number, b: number): Comparator;
11-
static not_between(a: number, b: number): Comparator;
12-
static like(expression: string): Comparator;
13-
static eq(value: any): Comparator;
14-
static ne(value: any): Comparator;
15-
static gt(value: any): Comparator;
16-
static gte(value: any): Comparator;
17-
static lt(value: any): Comparator;
18-
static lte(value: any): Comparator;
10+
static Comparators: string[];
11+
static between(a: number, b: number): Comparator;
12+
static not_between(a: number, b: number): Comparator;
13+
static like(expression: string): Comparator;
14+
static eq(value: any): Comparator;
15+
static ne(value: any): Comparator;
16+
static gt(value: any): Comparator;
17+
static gte(value: any): Comparator;
18+
static lt(value: any): Comparator;
19+
static lte(value: any): Comparator;
1920

20-
escapeId(id: string): string;
21-
escapeId(id: string, table: string): string;
22-
escapeVal(value: any): string;
23-
select(): SelectQuery;
24-
insert(): InsertQuery;
25-
update(): UpdateQuery;
26-
remove(): RemoveQuery;
27-
}
21+
escapeId(id: string): string;
22+
escapeId(id: string, table: string): string;
23+
escapeVal(value: any): string;
24+
select(): SelectQuery;
25+
insert(): InsertQuery;
26+
update(): UpdateQuery;
27+
remove(): RemoveQuery;
28+
}
2829

29-
export interface Comparator {
30-
sql_comparator(): string;
31-
from?: any;
32-
to?: any;
33-
expr?: string;
34-
value?: any;
35-
}
30+
export interface Comparator {
31+
sql_comparator(): string;
32+
from?: any;
33+
to?: any;
34+
expr?: string;
35+
value?: any;
36+
}
3637

37-
export interface TextQuery {
38-
data: any;
39-
type: string;
40-
}
38+
export interface TextQuery {
39+
data: any;
40+
type: string;
41+
}
4142

42-
export interface SelectQuery {
43-
select(fields: string): SelectQuery;
44-
calculateFoundRows: SelectQuery;
45-
as(alias: string): SelectQuery;
46-
fun(fun: string, column: string, alias: string): SelectQuery;
47-
from(table: string, from_id: string, to_id: string): SelectQuery;
48-
from(table: string, from_id: string, to_table: string, to_id: string): SelectQuery;
49-
where(...args: any[]): SelectQuery;
50-
whereExists(table: string, table_link: string, link: string, conditions: { [column: string]: any }): SelectQuery;
51-
groupBy(...columns: string[]): SelectQuery;
52-
offset(offset: number): SelectQuery;
53-
limit(limit: number): SelectQuery;
54-
order(column: string, direction: string): SelectQuery;
55-
build(): string;
56-
}
43+
export interface SelectQuery {
44+
select(fields: string): SelectQuery;
45+
calculateFoundRows: SelectQuery;
46+
as(alias: string): SelectQuery;
47+
fun(fun: string, column: string, alias: string): SelectQuery;
48+
from(table: string, from_id: string, to_id: string): SelectQuery;
49+
from(table: string, from_id: string, to_table: string, to_id: string): SelectQuery;
50+
where(...args: any[]): SelectQuery;
51+
whereExists(table: string, table_link: string, link: string, conditions: { [column: string]: any }): SelectQuery;
52+
groupBy(...columns: string[]): SelectQuery;
53+
offset(offset: number): SelectQuery;
54+
limit(limit: number): SelectQuery;
55+
order(column: string, direction: string): SelectQuery;
56+
build(): string;
57+
}
5758

58-
export interface InsertQuery {
59-
into(table: string): InsertQuery;
60-
set(values: { [key: string]: any }[]): InsertQuery;
61-
build(): string;
62-
}
59+
export interface InsertQuery {
60+
into(table: string): InsertQuery;
61+
set(values: { [key: string]: any }[]): InsertQuery;
62+
build(): string;
63+
}
6364

64-
export interface UpdateQuery {
65-
into(table: string): UpdateQuery;
66-
set(values: { [column: string]: any }): UpdateQuery;
67-
where(...conditions: { [column: string]: any }[]): UpdateQuery;
68-
build(): string;
69-
}
65+
export interface UpdateQuery {
66+
into(table: string): UpdateQuery;
67+
set(values: { [column: string]: any }): UpdateQuery;
68+
where(...conditions: { [column: string]: any }[]): UpdateQuery;
69+
build(): string;
70+
}
7071

71-
export interface RemoveQuery {
72-
from(table: string): RemoveQuery;
73-
where(...conditions: { [column: string]: any }[]): RemoveQuery;
74-
build(): string;
72+
export interface RemoveQuery {
73+
from(table: string): RemoveQuery;
74+
where(...conditions: { [column: string]: any }[]): RemoveQuery;
75+
build(): string;
76+
}
7577
}
78+
export = sqlquery;
7679
}

0 commit comments

Comments
 (0)