-
Notifications
You must be signed in to change notification settings - Fork 10
/
index_getFromLocalDiskToStore.html
255 lines (234 loc) · 8.28 KB
/
index_getFromLocalDiskToStore.html
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
<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
<title>Stencil Component Test DB Get From HTTP Request</title>
<script type="module" src="/build/jeep-sqlite.esm.js"></script>
<script nomodule src="/build/jeep-sqlite.js"></script>
</head>
<style>
/* Navbar container */
.navbar {
overflow: hidden;
background-color: #333;
font-family: Arial;
}
/* Links inside the navbar */
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* The dropdown container */
.dropdown {
float: left;
overflow: hidden;
}
/* Dropdown button */
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit; /* Important for vertical align on mobile phones */
margin: 0; /* Important for vertical align on mobile phones */
}
/* Add a red background color to navbar links on hover */
.navbar a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
/* Dropdown content (hidden by default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* Add a grey background color to dropdown links on hover */
.dropdown-content a:hover {
background-color: #ddd;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
.container {
margin-left: 25px;
}
</style>
<body>
<div class="navbar">
<a href="index.html">Home</a>
<div class="dropdown">
<button class="dropbtn">Tests
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="index_issue230.html">Issue#230 Test</a>
<a href="index_delete.html">Delete Tests Page</a>
<a href="index_deleteFKC.html">Delete FKC Tests Page</a>
<a href="index_page1_issue11.html">Page 1 Issue11 Tests Page</a>
<a href="index_page2_issue11.html">Page 2 Issue11 Tests Page</a>
<a href="index_incremental_upgrade_version.html">New Incremental Upgrade Version</a>
<a href="index_readonly.html">DB Readonly</a>
<a href="index_getFromHTTP.html">DB Get FROM HTTP Request</a>
<a href="index_concurrent.html">DB Concurrent Test</a>
<a href="index_issue385.html">Issue#385 Test</a>
<a href="index_getFromLocalDiskToStore.html">DB Get FROM Local Disk to Store</a>
<a href="index_returning.html">DB Test RETURNING</a>
<a href="index_issue445.html">DB Test issue445</a>
<a href="index_transaction.html">DB Test Transactions</a>
<a href="index_issue498.html">DB Test Issue498</a>
<a href="index_issue504.html">DB Test Issue504</a>
<a href="index_issue37.html">DB Test Issue37</a>
</div>
</div>
</div>
<h1>Get From Local Disk To Store</h1>
<div class="container">
<h2 class="message"></h2>
</div>
<jeep-sqlite></jeep-sqlite>
</body>
</html>
<script>
(async () => {
const messageEl = document.querySelector('.message');
await customElements.whenDefined('jeep-sqlite');
const jeepSqlite = document.querySelector('jeep-sqlite');
// Test button's text
jeepSqlite.pickText = "Select a Database";
// Test button's style
jeepSqlite.buttonOptions = '{"backgroundColor":"#000000", "top":"70%","fontSize":"1.5em"}';
const startTest = async (name) => {
console.log(`************************************`);
console.log(`* Starting ${name} *`);
console.log(`************************************\n\n`);
};
const endTest = async(name,msg) => {
if(msg.length === 0) {
const message = `* The set of tests ${name} was successful *`
console.log(`\n${message}\n`);
messageEl.innerHTML = message;
} else {
const message = `${msg}\n* The set of tests ${name} failed *\n`
console.log(`${message}`);
messageEl.innerHTML = message;
}
}
const openDB = async (dbName) => {
try {
// create connection to dbName
await jeepSqlite.createConnection({database:dbName, version: 1});
console.log(`after create connection`);
// open db dbName
await jeepSqlite.open({database: dbName});
// Select all tables,
ret = await jeepSqlite.getTableList({database: dbName});
console.log(`>>> openDB getTableList ret: ${JSON.stringify(ret)} `)
if(ret.values.length > 0) {
for (const tableName of ret.values) {
const retQuery = await jeepSqlite.query({database: dbName, statement:`SELECT * FROM ${tableName};`});
console.log(`*** table: ${tableName} ***`);
console.log(`${JSON.stringify(retQuery.values)}`);
}
}
// Do some new stuff here
// Save the database to disk
await jeepSqlite.saveToLocalDisk({database:dbName});
return Promise.resolve();
} catch (err) {
let msg = err.message ? err.message : err;
console.log(`Error: ${msg}`);
return Promise.reject(msg);
}
}
jeepSqlite.addEventListener('jeepSqlitePickDatabaseEnded', async (event) => {
if(event.detail.db_name) {
await openDB(event.detail.db_name);
console.log(`>>> openDB successful <<<`)
} else {
console.log(`${event.detail.message}`);
}
});
jeepSqlite.addEventListener('jeepSqliteSaveDatabaseToDisk', async (event) => {
if(event.detail.db_name) {
const dbName = event.detail.db_name.split("SQLite.db")[0];
console.log(`in jeepSqliteSaveDatabaseToDisk dbName: ${dbName}`);
try {
// Close the connection
await jeepSqlite.closeConnection({database:dbName});
console.log(`******** saveDB successful ********\n`)
await endTest(activeTest,'');
} catch (err) {
let msg = err.message ? err.message : err;
await endTest(activeTest,`${event.detail.message}`);
}
} else {
console.log(`${event.detail.message}`);
await endTest(activeTest,`${event.detail.message}`);
}
});
if(await jeepSqlite.isStoreOpen()) {
const initializeTest = async() => {
try {
// test the plugin with echo
let res = await jeepSqlite.echo({value:"Hello from echo"});
if(res.value !== "Hello from echo"){
const msg = `Error: Echo not returning "Hello from echo"\n`;
return Promise.reject(msg);
}
console.log("> Echo successful\n");
console.log(`******** initializeTest successful ********\n`)
return Promise.resolve();
} catch (err) {
let msg = err.message ? err.message : err;
console.log(`Error: ${msg}`);
return Promise.reject(msg);
}
}
const readDB = async () => {
try {
await jeepSqlite.getFromLocalDiskToStore({overwrite: true});
return Promise.resolve();
} catch (err) {
let msg = err.message ? err.message : err;
console.log(`Error: ${msg}`);
return Promise.reject(msg);
}
}
// ********************************
// *** test with SQL statements ***
// ********************************
try {
var activeTest = 'DatabaseGetFromLocalDisk';
// test standard SQL statements
await startTest(activeTest);
// initialize the database
await initializeTest();
await readDB();
} catch (err) {
let msg = err.message ? err.message : err;
console.log(`Error: ${msg}`);
await endTest(activeTest,msg);
}
}
})();
</script>