-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
87 lines (77 loc) · 3.39 KB
/
index.html
File metadata and controls
87 lines (77 loc) · 3.39 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Driver | SQLite Cloud</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="../../lib/sqlitecloud.drivers.js"></script>
</head>
<body class="p-4">
<h1>SQLite Cloud Drivers</h1>
<div class="pb-6 text-sm">
<a href="https://www.npmjs.com/package/@sqlitecloud/drivers">npm add @sqlitecloud/drivers</a>
</div>
<!-- Add the text field and button here -->
<div class="pb-2">
<div class="text-xs w-12">databaseUrl</div>
<input type="text" id="connectionStringInput"
placeholder="Example: sqlitecloud://admin:password@host.sqlite.cloud:8860/chinook.sqlite"
value="sqlitecloud://host.sqlite.cloud:8860?apikey=apikey" class="border rounded w-full pl-2 pr-2 mb-2" />
<div class="text-sm w-12">sql:</div>
<input type="text" id="messageInput"
placeholder="Example: USE DATABASE chinook.sqlite; select * from customers limit 3"
value="USE DATABASE chinook.sqlite; select * from customers limit 3"
class="border rounded w-full pl-2 pr-2 mb-2" />
</div>
<button id="sendButton" class="border rounded w-32 mb-6">query</button>
<h2 class="pb-4">Results:</h2>
<ul id="messages" class="pl-4"></ul>
<script type="module">
const status = document.getElementById('status');
const messages = document.getElementById('messages');
const appendMessage = (content) => {
const item = document.createElement('li');
item.classList.add('pb-4');
item.classList.add('text-sm');
item.textContent = content;
messages.prepend(item);
};
sendButton.addEventListener('click', () => {
// Get the input element by ID
var connectionStringinputElement = document.getElementById('connectionStringInput');
var connectionstring = connectionStringinputElement.value;
// connect via websocket to the gateway on the same server
const connectionConfig = {
gatewayUrl: `${window.location.protocol === 'https:' ? 'wss' : 'ws'
}://${window.location.hostname}:443`,
connectionstring: connectionstring,
};
var database = new window.sqlitecloud.Database(
connectionConfig,
(error) => {
if (error) {
database = null;
appendMessage(`connection error: ${error}`);
} else {
console.log('connected');
appendMessage(`connected`);
}
}
);
var messageInputElement = document.getElementById('messageInput');
const sql = messageInputElement.value;
const startTime = Date.now();
// send an async sql request to the server
database.all(sql, (error, rows) => {
if (error) {
console.error(`sql: ${sql}, error: ${error}`, error);
appendMessage(`sql: ${sql}, error: ${error}`);
} else {
console.debug(`sql: ${sql}, (${Date.now() - startTime}ms)`, rows);
appendMessage(JSON.stringify(rows));
}
});
});
</script>
</body>
</html>