-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
web_sql_dart2js.dart
307 lines (258 loc) · 9.7 KB
/
web_sql_dart2js.dart
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/**
* An API for storing data in the browser that can be queried with SQL.
*
* **Caution:** this specification is no longer actively maintained by the Web
* Applications Working Group and may be removed at any time.
* See [the W3C Web SQL Database specification](http://www.w3.org/TR/webdatabase/)
* for more information.
*
* The [dart:indexed_db] APIs is a recommended alternatives.
*
* {@category Web}
*/
library dart.dom.web_sql;
import 'dart:async';
import 'dart:collection' hide LinkedList, LinkedListEntry;
import 'dart:_internal' show FixedLengthListMixin;
import 'dart:html';
import 'dart:html_common';
import 'dart:_foreign_helper' show JS;
import 'dart:_interceptors' show Interceptor;
// DO NOT EDIT - unless you are editing documentation as per:
// https://code.google.com/p/dart/wiki/ContributingHTMLDocumentation
// Auto-generated dart:audio library.
import 'dart:_js_helper'
show
applyExtension,
convertDartClosureToJS,
Creates,
JSName,
Native,
JavaScriptIndexingBehavior,
Returns;
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// WARNING: Do not edit - generated code.
typedef void SqlStatementCallback(
SqlTransaction transaction, SqlResultSet resultSet);
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// WARNING: Do not edit - generated code.
typedef void SqlStatementErrorCallback(
SqlTransaction transaction, SqlError error);
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// WARNING: Do not edit - generated code.
typedef void SqlTransactionCallback(SqlTransaction transaction);
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// WARNING: Do not edit - generated code.
typedef void SqlTransactionErrorCallback(SqlError error);
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@SupportedBrowser(SupportedBrowser.CHROME)
@SupportedBrowser(SupportedBrowser.SAFARI)
@Native("Database")
class SqlDatabase extends Interceptor {
// To suppress missing implicit constructor warnings.
factory SqlDatabase._() {
throw new UnsupportedError("Not supported");
}
/// Checks if this type is supported on the current platform.
static bool get supported => JS('bool', '!!(window.openDatabase)');
String? get version native;
@JSName('changeVersion')
/**
* Atomically update the database version to [newVersion], asynchronously
* running [callback] on the [SqlTransaction] representing this
* [changeVersion] transaction.
*
* If [callback] runs successfully, then [successCallback] is called.
* Otherwise, [errorCallback] is called.
*
* [oldVersion] should match the database's current [version] exactly.
*
* See also:
*
* * [Database.changeVersion](http://www.w3.org/TR/webdatabase/#dom-database-changeversion) from W3C.
*/
void _changeVersion(String oldVersion, String newVersion,
[SqlTransactionCallback? callback,
SqlTransactionErrorCallback? errorCallback,
VoidCallback? successCallback]) native;
@JSName('changeVersion')
/**
* Atomically update the database version to [newVersion], asynchronously
* running [callback] on the [SqlTransaction] representing this
* [changeVersion] transaction.
*
* If [callback] runs successfully, then [successCallback] is called.
* Otherwise, [errorCallback] is called.
*
* [oldVersion] should match the database's current [version] exactly.
*
* See also:
*
* * [Database.changeVersion](http://www.w3.org/TR/webdatabase/#dom-database-changeversion) from W3C.
*/
Future<SqlTransaction> changeVersion(String oldVersion, String newVersion) {
var completer = new Completer<SqlTransaction>();
_changeVersion(oldVersion, newVersion, (value) {
completer.complete(value);
}, (error) {
completer.completeError(error);
});
return completer.future;
}
@JSName('readTransaction')
void _readTransaction(SqlTransactionCallback callback,
[SqlTransactionErrorCallback? errorCallback,
VoidCallback? successCallback]) native;
@JSName('readTransaction')
Future<SqlTransaction> readTransaction() {
var completer = new Completer<SqlTransaction>();
_readTransaction((value) {
completer.complete(value);
}, (error) {
completer.completeError(error);
});
return completer.future;
}
void transaction(SqlTransactionCallback callback,
[SqlTransactionErrorCallback? errorCallback,
VoidCallback? successCallback]) native;
@JSName('transaction')
Future<SqlTransaction> transaction_future() {
var completer = new Completer<SqlTransaction>();
transaction((value) {
applyExtension('SQLTransaction', value);
completer.complete(value);
}, (error) {
completer.completeError(error);
});
return completer.future;
}
}
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@Native("SQLError")
class SqlError extends Interceptor {
// To suppress missing implicit constructor warnings.
factory SqlError._() {
throw new UnsupportedError("Not supported");
}
static const int CONSTRAINT_ERR = 6;
static const int DATABASE_ERR = 1;
static const int QUOTA_ERR = 4;
static const int SYNTAX_ERR = 5;
static const int TIMEOUT_ERR = 7;
static const int TOO_LARGE_ERR = 3;
static const int UNKNOWN_ERR = 0;
static const int VERSION_ERR = 2;
int? get code native;
String? get message native;
}
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@Native("SQLResultSet")
class SqlResultSet extends Interceptor {
// To suppress missing implicit constructor warnings.
factory SqlResultSet._() {
throw new UnsupportedError("Not supported");
}
int? get insertId native;
SqlResultSetRowList? get rows native;
int? get rowsAffected native;
}
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@Native("SQLResultSetRowList")
class SqlResultSetRowList extends Interceptor
with ListMixin<Map>, ImmutableListMixin<Map>
implements List<Map> {
// To suppress missing implicit constructor warnings.
factory SqlResultSetRowList._() {
throw new UnsupportedError("Not supported");
}
int get length => JS("int", "#.length", this);
Map operator [](int index) {
if (JS("bool", "# >>> 0 !== # || # >= #", index, index, index, length))
throw new RangeError.index(index, this);
return this.item(index)!;
}
void operator []=(int index, Map value) {
throw new UnsupportedError("Cannot assign element of immutable List.");
}
// -- start List<Map> mixins.
// Map is the element type.
set length(int value) {
throw new UnsupportedError("Cannot resize immutable List.");
}
Map get first {
if (this.length > 0) {
return JS('Map', '#[0]', this);
}
throw new StateError("No elements");
}
Map get last {
int len = this.length;
if (len > 0) {
return JS('Map', '#[#]', this, len - 1);
}
throw new StateError("No elements");
}
Map get single {
int len = this.length;
if (len == 1) {
return JS('Map', '#[0]', this);
}
if (len == 0) throw new StateError("No elements");
throw new StateError("More than one element");
}
Map elementAt(int index) => this[index];
// -- end List<Map> mixins.
Map? item(int index) {
return convertNativeToDart_Dictionary(_item_1(index));
}
@JSName('item')
_item_1(index) native;
}
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
@SupportedBrowser(SupportedBrowser.CHROME)
@SupportedBrowser(SupportedBrowser.SAFARI)
// http://www.w3.org/TR/webdatabase/#sqltransaction
@deprecated // deprecated
@Native("SQLTransaction")
class SqlTransaction extends Interceptor {
// To suppress missing implicit constructor warnings.
factory SqlTransaction._() {
throw new UnsupportedError("Not supported");
}
@JSName('executeSql')
void _executeSql(String sqlStatement,
[List? arguments,
SqlStatementCallback? callback,
SqlStatementErrorCallback? errorCallback]) native;
@JSName('executeSql')
Future<SqlResultSet> executeSql(String sqlStatement, [List? arguments]) {
var completer = new Completer<SqlResultSet>();
_executeSql(sqlStatement, arguments, (transaction, resultSet) {
applyExtension('SQLResultSet', resultSet);
applyExtension('SQLResultSetRowList', resultSet.rows);
completer.complete(resultSet);
}, (transaction, error) {
completer.completeError(error);
});
return completer.future;
}
}