Skip to content

Commit a609923

Browse files
Fixed callbacks in tests, build scripts
1 parent b4ea867 commit a609923

File tree

12 files changed

+399
-388
lines changed

12 files changed

+399
-388
lines changed

.devcontainer/devcontainer.json

Lines changed: 0 additions & 29 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"gateway-dev": "bun --watch ./src/gateway/gateway.ts",
1919
"gateway-start": "bun --smol run ./src/gateway/gateway.ts",
2020
"gateway-test": "bun test ./src/gateway/connection-bun.test.ts --watch --coverage",
21-
"gateway-build": "bun build ./src/gateway/gateway.ts --compile --outfile ./lib/sqlitecloud-gateway.out"
21+
"gateway-build": "./scripts/gateway-build.sh"
2222
},
2323
"repository": {
2424
"type": "git",

public/sqlitecloud.drivers.dev.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/sqlitecloud.drivers.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/gateway-build.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
# gateway-build.sh - build gateway as self contained executable for linux and macos
3+
# If you get an error executing this script run:
4+
# chmod u+x ./scripts/build.sh
5+
6+
# navigate to the script's directory
7+
#cd "$(dirname "$0")"
8+
9+
# build bun's one file binary
10+
mkdir -p ./lib/gateway/public
11+
bun build ./src/gateway/gateway.ts --compile --outfile ./lib/gateway/gateway.out
12+
13+
# copy the public folder to the build folder
14+
cp -r ./public/* ./lib/gateway/public/
15+
cp ./package.json ./lib/gateway/

scripts/gateway-upgrade.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# upgrade.sh - upload gateway builds to a couple of nodes used for development, restart gateway
3+
#
4+
5+
# upload ./build/ to test nodes
6+
# frankfurt01, frankfurt02, ny01
7+
rsync -avz -e "ssh -i ~/.ssh/id_ed25519" ./build/ sqlitecloud@y8pbz99zp.sqlite.cloud:gateway
8+
rsync -avz -e "ssh -i ~/.ssh/id_ed25519" ./build/ sqlitecloud@oggdnp3zm.sqlite.cloud:gateway
9+
10+
# connect to nodes using ssh key
11+
# ssh -i ~/.ssh/id_ed25519 sqlitecloud@y8pbz99zp.sqlite.cloud
12+
# ssh -i ~/.ssh/id_ed25519 sqlitecloud@og0wjec-m.sqlite.cloud
13+
14+
# restart gateway (locally)
15+
# pkill gateway-linux-x; cd /home/sqlitecloud/gateway; nohup ./gateway-linux-x64.out
16+
17+
# restart gateway (remotely)
18+
ssh -i ~/.ssh/id_ed25519 sqlitecloud@y8pbz99zp.sqlite.cloud 'pkill gateway-linux-x; cd /home/sqlitecloud/gateway; nohup ./gateway-linux-x64.out > /dev/null 2>&1 &'
19+
ssh -i ~/.ssh/id_ed25519 sqlitecloud@oggdnp3zm.sqlite.cloud 'pkill gateway-linux-x; cd /home/sqlitecloud/gateway; nohup ./gateway-linux-x64.out > /dev/null 2>&1 &'

scripts/sqlitecloud-cli

2.59 MB
Binary file not shown.

src/drivers/protocol.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import { SQLiteCloudError, type SQLCloudRowsetMetadata, type SQLiteCloudDataTypes } from './types'
66
import { SQLiteCloudRowset } from './rowset'
7-
import { debug } from 'console'
87

98
const lz4 = require('lz4js')
109

@@ -222,7 +221,7 @@ export function parseRowsetChunks(buffers: Buffer[]): SQLiteCloudRowset {
222221
console.assert(dataType === CMD_ROWSET_CHUNK)
223222
buffer = buffer.subarray(buffer.indexOf(' ') + 1)
224223

225-
while (true) {
224+
while (buffer.length > 0 && !bufferStartsWith(buffer, ROWSET_CHUNKS_END)) {
226225
// chunk header, eg: 0:VERS NROWS NCOLS
227226
const { index: chunkIndex, metadata: chunkMetadata, fwdBuffer } = parseRowsetHeader(buffer)
228227
buffer = fwdBuffer
@@ -241,11 +240,6 @@ export function parseRowsetChunks(buffers: Buffer[]): SQLiteCloudRowset {
241240
data.push(itemData)
242241
buffer = fwdBuffer
243242
}
244-
245-
// no more chunks?
246-
if (bufferStartsWith(buffer, ROWSET_CHUNKS_END)) {
247-
break
248-
}
249243
}
250244

251245
console.assert(data && data.length === metadata.numberOfRows * metadata.numberOfColumns, 'parseRowsetChunks - invalid rowset data')

src/gateway/connection-bun.test.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
//
44

55
// MUST RUN USING BUN TEST RUNNER, EG:
6-
// bun test ./src/gateway/gateway.test.ts --watch
6+
// bun test connection-bun.test.ts --watch
77

88
import { SQLiteCloudError } from '../drivers/types'
99
import { SQLiteCloudBunConnection } from './connection-bun'
10+
import { expect, test, describe, beforeEach, afterEach } from 'bun:test'
1011

1112
let CHINOOK_DATABASE_URL = process.env['CHINOOK_DATABASE_URL'] as string
1213
console.assert(CHINOOK_DATABASE_URL, 'CHINOOK_DATABASE_URL is required')
13-
CHINOOK_DATABASE_URL = 'sqlitecloud://admin:uN3ARhdcKQ@oggdnp3zm.sqlite.cloud:8860/chinook.db?verbose=true'
14-
15-
import { expect, test, describe, beforeEach, afterEach } from 'bun:test'
1614

1715
async function getConnection(): Promise<SQLiteCloudBunConnection> {
1816
return new Promise((resolve, reject) => {
@@ -39,8 +37,8 @@ async function sendCommands(connection: SQLiteCloudBunConnection, command: strin
3937
describe('SQLiteCloudBunConnection', () => {
4038
// test different ways to connect
4139
describe('connecting', () => {
42-
test('can connect using bun socket', async done => {
43-
const connection = new SQLiteCloudBunConnection(CHINOOK_DATABASE_URL, error => {
40+
test('can connect using bun socket', done => {
41+
new SQLiteCloudBunConnection(CHINOOK_DATABASE_URL, error => {
4442
if (error) {
4543
console.error('Error connecting to database', error)
4644
}
@@ -129,10 +127,11 @@ describe('SQLiteCloudBunConnection', () => {
129127
expect(bufferrowset.length).toBe(0)
130128
})
131129

132-
test('should test error', async done => {
130+
test('should test error', done => {
133131
chinookConnection.sendCommands('TEST ERROR', (error, results) => {
134132
expect(error).toBeDefined()
135133
expect(error).toBeInstanceOf(SQLiteCloudError)
134+
expect(results).toBeNull()
136135

137136
const sqliteCloudError = error as SQLiteCloudError
138137
expect(sqliteCloudError.message).toBe('This is a test error message with a devil error code.')
@@ -144,10 +143,11 @@ describe('SQLiteCloudBunConnection', () => {
144143
})
145144
})
146145

147-
test('should test exterror', async done => {
146+
test('should test exterror', done => {
148147
chinookConnection.sendCommands('TEST EXTERROR', (error, results) => {
149148
expect(error).toBeDefined()
150149
expect(error).toBeInstanceOf(SQLiteCloudError)
150+
expect(results).toBeNull()
151151

152152
const sqliteCloudError = error as SQLiteCloudError
153153
expect(sqliteCloudError.message).toBe('This is a test error message with an extcode and a devil error code.')
@@ -193,7 +193,7 @@ describe('SQLiteCloudBunConnection', () => {
193193

194194
// various select statements
195195
describe('select', () => {
196-
test('can run simple select', async done => {
196+
test('can run simple select', done => {
197197
const connection = new SQLiteCloudBunConnection(CHINOOK_DATABASE_URL, error => {
198198
if (error) {
199199
done(error)
@@ -230,7 +230,8 @@ describe('SQLiteCloudBunConnection', () => {
230230
const connection = await getConnection()
231231

232232
let sql = ''
233-
for (var i = 0; i < 250; i++) {
233+
let i = 0
234+
for (; i < 250; i++) {
234235
sql += `SELECT ${i} AS counter; `
235236
}
236237

src/gateway/connection-bun.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ export class SQLiteCloudBunConnection extends SQLiteCloudConnection {
3333
}
3434

3535
/* Opens a connection with the server and sends the initialization commands. Will throw in case of errors. */
36+
/* eslint-disable @typescript-eslint/no-unused-vars */
3637
connectTransport(config: SQLiteCloudConfig, callback?: ErrorCallback): this {
37-
console.debug(`-> connecting ${config?.host}:${config?.port}`)
38+
console.debug(`-> connecting ${config?.host as string}:${config?.port as number}`)
3839
console.assert(!this.connected, 'BunSocketTransport.connect - connection already established')
3940
this.config = config
4041

41-
Bun.connect<any>({
42+
void Bun.connect<any>({
4243
hostname: config.host as string,
4344
port: config.port as number,
4445
tls: config.insecure ? false : true,
@@ -50,7 +51,8 @@ export class SQLiteCloudBunConnection extends SQLiteCloudConnection {
5051

5152
// send initialization commands
5253
const commands = getInitializationCommands(config)
53-
this.transportCommands(commands, (error, rowset) => {
54+
this.transportCommands(commands, error => {
55+
// any results are ignored
5456
if (error) {
5557
console.error('BunSocketTransport.connect - error initializing connection', error)
5658
callback?.call(this, error)
@@ -63,7 +65,7 @@ export class SQLiteCloudBunConnection extends SQLiteCloudConnection {
6365

6466
// connection failed
6567
connectError: (socket, error) => {
66-
console.error(`BunTransport.connect - connectError: ${error}`)
68+
console.error('BunTransport.connect - connectError', error)
6769
this.close()
6870
callback?.call(this, error)
6971
},
@@ -106,7 +108,7 @@ export class SQLiteCloudBunConnection extends SQLiteCloudConnection {
106108
}
107109
})
108110
.catch(error => {
109-
console.debug(`BunTransport.connect - error: ${error}`)
111+
console.debug('BunTransport.connect - error', error)
110112
this.close()
111113
callback?.call(this, error)
112114
})

0 commit comments

Comments
 (0)