forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lovefield.d.ts
235 lines (197 loc) · 6.62 KB
/
lovefield.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
// Type definitions for Lovefield v2.0.62
// Project: http://google.github.io/lovefield/
// Definitions by: freshp86 <https://github.com/freshp86>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../es6-promise/es6-promise.d.ts"/>
declare module lf {
export enum Order { ASC, DESC }
export enum Type {
ARRAY_BUFFER,
BOOLEAN,
DATE_TIME,
INTEGER,
NUMBER,
OBJECT,
STRING
}
export enum ConstraintAction {
RESTRICT,
CASCADE
}
export enum ConstraintTiming {
IMMEDIATE,
DEFERRABLE
}
export interface Binder {
getIndex(): number
}
export interface Predicate {}
export interface Row {}
type ValueLiteral = string|number|boolean|Date;
export interface PredicateProvider {
eq(operand: ValueLiteral|schema.Column|Binder): Predicate
neq(operand: ValueLiteral|schema.Column|Binder): Predicate
lt(operand: ValueLiteral|schema.Column|Binder): Predicate
lte(operand: ValueLiteral|schema.Column|Binder): Predicate
gt(operand: ValueLiteral|schema.Column|Binder): Predicate
gte(operand: ValueLiteral|schema.Column|Binder): Predicate
match(operand: RegExp|Binder): Predicate
between(from: ValueLiteral|Binder, to: ValueLiteral|Binder): Predicate
in(values: Binder|Array<ValueLiteral>): Predicate
isNull(): Predicate
isNotNull(): Predicate
}
function bind(index: number): Binder;
export interface Transaction {
attach(query: query.Builder): Promise<Array<Object>>
begin(scope: Array<schema.Table>): Promise<void>
commit(): Promise<void>
exec(queries: Array<query.Builder>): Promise<Array<Array<Object>>>
rollback(): Promise<void>
}
export enum TransactionType { READ_ONLY, READ_WRITE }
export interface Database {
close(): void
createTransaction(type?: TransactionType): Transaction
delete(): query.Delete
export(): Promise<Object>
getSchema(): schema.Database
import(data: Object): Promise<void>
insertOrReplace(): query.Insert
insert(): query.Insert
observe(query: query.Select, callback: Function): void
select(...columns: schema.Column[]): query.Select
unobserve(query: query.Select, callback: Function): void
update(table: schema.Table): query.Update
}
module query {
export interface Builder {
bind(...values: any[]): Builder
exec(): Promise<Array<Object>>
explain(): string
toSql(): string
}
export interface Delete extends Builder {
from(table: schema.Table): Delete
where(predicate: Predicate): Delete
}
export interface Insert extends Builder {
into(table: schema.Table): Insert
values(rows: Array<Row>|Binder|Array<Binder>): Insert
}
export interface Select extends Builder {
from(...tables: schema.Table[]): Select
groupBy(...columns: schema.Column[]): Select
innerJoin(table: schema.Table, predicate: Predicate): Select
leftOuterJoin(table: schema.Table, predicate: Predicate): Select
limit(numberOfRows: Binder|number): Select
orderBy(column: schema.Column, order?: Order): Select
skip(numberOfRows: Binder|number): Select
where(predicate: Predicate): Select
}
export interface Update extends Builder {
set(column: schema.Column, value: any): Update
where(predicate: Predicate): Update
}
} // module query
module raw {
export interface BackStore {
getRawDBInstance(): any
getRawTransaction(): any
dropTable(tableName: string): Promise<void>
addTableColumn(
tableName: string, columnName: string,
defaultValue: string|boolean|number|Date|ArrayBuffer): Promise<void>
dropTableColumn(tableName: string, columnName:string): Promise<void>
renameTableColumn(
tableName: string, oldColumnName: string,
newColumnName:string) : Promise<void>
createRow(payload: Object): Row
getVersion(): number
dump(): Array<Object>
}
} // module raw
module schema {
export enum DataStoreType {
FIREBASE,
INDEXED_DB,
LOCAL_STORAGE,
MEMORY,
WEB_SQL
}
export interface DatabasePragma {
enableBundledMode: boolean
}
export interface Database {
name(): string
pragma(): DatabasePragma
tables(): Array<schema.Table>
table(tableName: string): schema.Table
version(): number
}
export interface Column extends PredicateProvider {
as(name: string): Column
getName(): string
getNormalizedName(): string
}
export interface Table {
as(name: string): Table
createRow(value: Object): Row
getName(): string
}
export interface ConnectOptions {
onUpgrade?: (rawDb: raw.BackStore) => Promise<void>
storeType?: DataStoreType
webSqlDbSize?: number
// TODO(dpapad): firebase?
}
export interface Builder {
connect(options: ConnectOptions): Promise<lf.Database>
createTable(tableName: string): TableBuilder
getSchema(): Database
setPragma(pragma: DatabasePragma): void
}
export interface IndexedColumn {
autoIncrement: boolean
name: string
order: Order
}
type RawForeignKeySpec = {
local: string
ref: string
action: lf.ConstraintAction
timing: lf.ConstraintAction
}
export interface TableBuilder {
addColumn(name: string, type: lf.Type): TableBuilder
addForeignKey(name: string, spec: RawForeignKeySpec): TableBuilder
addIndex(
name: string, columns: Array<string>|Array<IndexedColumn>,
unique?: boolean, order?: Order): TableBuilder
addNullable(columns: Array<string>): TableBuilder
addPrimaryKey(
columns: Array<string>|Array<IndexedColumn>,
autoInc?: boolean): TableBuilder
addUnique(name: string, columns: Array<string>): TableBuilder
}
function create(dbName: string, dbVersion: number): Builder
} // module schema
module op {
function and(...args: Predicate[]): Predicate;
function not(operand: Predicate): Predicate;
function or(...args: Predicate[]): Predicate;
} // module op
module fn {
function avg(column: schema.Column): schema.Column
function count(column?: schema.Column): schema.Column
function distinct(column: schema.Column): schema.Column
function geomean(column: schema.Column): schema.Column
function max(column: schema.Column): schema.Column
function min(column: schema.Column): schema.Column
function stddev(column: schema.Column): schema.Column
function sum(column: schema.Column): schema.Column
} // module fn
} // module lf
declare module 'lf' {
export = lf;
}