Skip to content

Commit 85276be

Browse files
author
Daniele Briggi
committed
fix(blob): blob to be sent as binary
1 parent bb15e13 commit 85276be

File tree

12 files changed

+38
-16
lines changed

12 files changed

+38
-16
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ dist
118118
# Compiled code
119119
coverage/
120120
docs/
121-
lib/
121+
#lib/
122122

123123
# Mac files
124124
.DS_Store

lib/drivers/connection.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* connection.ts - base abstract class for sqlitecloud server connections
33
*/
4-
import { SQLiteCloudConfig, ErrorCallback, ResultsCallback, SQLiteCloudCommand } from './types';
4+
import { SQLiteCloudConfig, ErrorCallback, ResultsCallback, SQLiteCloudCommand, SQLiteCloudDataTypes } from './types';
55
import { OperationsQueue } from './queue';
66
/**
77
* Base class for SQLiteCloudConnection handles basics and defines methods.
@@ -39,7 +39,7 @@ export declare abstract class SQLiteCloudConnection {
3939
* @returns An array of rows in case of selections or an object with
4040
* metadata in case of insert, update, delete.
4141
*/
42-
sql(sql: TemplateStringsArray | string | SQLiteCloudCommand, ...values: any[]): Promise<any>;
42+
sql(sql: TemplateStringsArray | string | SQLiteCloudCommand, ...values: SQLiteCloudDataTypes[]): Promise<any>;
4343
/** Disconnect from server, release transport. */
4444
abstract close(): this;
4545
}

lib/drivers/database.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import EventEmitter from 'eventemitter3';
22
import { PubSub } from './pubsub';
33
import { Statement } from './statement';
4-
import { ErrorCallback as ConnectionCallback, ResultsCallback, RowCallback, RowCountCallback, RowsCallback, SQLiteCloudCommand, SQLiteCloudConfig } from './types';
4+
import { ErrorCallback as ConnectionCallback, ResultsCallback, RowCallback, RowCountCallback, RowsCallback, SQLiteCloudCommand, SQLiteCloudConfig, SQLiteCloudDataTypes } from './types';
55
/**
66
* Creating a Database object automatically opens a connection to the SQLite database.
77
* When the connection is established the Database object emits an open event and calls
@@ -153,7 +153,7 @@ export declare class Database extends EventEmitter {
153153
* @returns An array of rows in case of selections or an object with
154154
* metadata in case of insert, update, delete.
155155
*/
156-
sql(sql: TemplateStringsArray | string | SQLiteCloudCommand, ...values: any[]): Promise<any>;
156+
sql(sql: TemplateStringsArray | string | SQLiteCloudCommand, ...values: SQLiteCloudDataTypes[]): Promise<any>;
157157
/**
158158
* Returns true if the database connection is open.
159159
*/

lib/drivers/protocol.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ function serializeCommand(data, zeroString = false) {
322322
}
323323
const bytesTotal = buffer_1.Buffer.byteLength(serializedData, 'utf-8');
324324
const header = `${exports.CMD_ARRAY}${bytesTotal} `;
325+
console.log(`serializeCommand - ${header}${serializedData}`);
325326
return header + serializedData;
326327
}
327328
function serializeData(data, zeroString = false) {
@@ -343,8 +344,8 @@ function serializeData(data, zeroString = false) {
343344
}
344345
}
345346
if (buffer_1.Buffer.isBuffer(data)) {
346-
const header = `${exports.CMD_BLOB}${data.length} `;
347-
return header + data.toString('utf-8');
347+
const header = `${exports.CMD_BLOB}${data.byteLength} `;
348+
return header + data;
348349
}
349350
if (data === null || data === undefined) {
350351
return `${exports.CMD_NULL} `;

lib/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.

lib/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.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sqlitecloud/drivers",
3-
"version": "1.0.491",
3+
"version": "1.0.492",
44
"description": "SQLiteCloud drivers for Typescript/Javascript in edge, web and node clients",
55
"main": "./lib/index.js",
66
"types": "./lib/index.d.ts",

src/drivers/connection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* connection.ts - base abstract class for sqlitecloud server connections
33
*/
44

5-
import { SQLiteCloudConfig, SQLiteCloudError, ErrorCallback, ResultsCallback, SQLiteCloudCommand } from './types'
5+
import { SQLiteCloudConfig, SQLiteCloudError, ErrorCallback, ResultsCallback, SQLiteCloudCommand, SQLiteCloudDataTypes } from './types'
66
import { validateConfiguration } from './utilities'
77
import { OperationsQueue } from './queue'
88
import { anonimizeCommand, getUpdateResults } from './utilities'
@@ -112,7 +112,7 @@ export abstract class SQLiteCloudConnection {
112112
* @returns An array of rows in case of selections or an object with
113113
* metadata in case of insert, update, delete.
114114
*/
115-
public async sql(sql: TemplateStringsArray | string | SQLiteCloudCommand, ...values: any[]): Promise<any> {
115+
public async sql(sql: TemplateStringsArray | string | SQLiteCloudCommand, ...values: SQLiteCloudDataTypes[]): Promise<any> {
116116
let commands = { query: '' } as SQLiteCloudCommand
117117

118118
// sql is a TemplateStringsArray, the 'raw' property is specific to TemplateStringsArray

src/drivers/database.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
SQLiteCloudArrayType,
2323
SQLiteCloudCommand,
2424
SQLiteCloudConfig,
25+
SQLiteCloudDataTypes,
2526
SQLiteCloudError
2627
} from './types'
2728
import { isBrowser, popCallback } from './utilities'
@@ -436,7 +437,7 @@ export class Database extends EventEmitter {
436437
* @returns An array of rows in case of selections or an object with
437438
* metadata in case of insert, update, delete.
438439
*/
439-
public async sql(sql: TemplateStringsArray | string | SQLiteCloudCommand, ...values: any[]): Promise<any> {
440+
public async sql(sql: TemplateStringsArray | string | SQLiteCloudCommand, ...values: SQLiteCloudDataTypes[]): Promise<any> {
440441
let commands = { query: '' } as SQLiteCloudCommand
441442

442443
// sql is a TemplateStringsArray, the 'raw' property is specific to TemplateStringsArray

src/drivers/protocol.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,8 @@ function serializeData(data: SQLiteCloudDataTypes, zeroString: boolean = false):
382382
}
383383

384384
if (Buffer.isBuffer(data)) {
385-
const header = `${CMD_BLOB}${data.length} `
386-
return header + data.toString('utf-8')
385+
const header = `${CMD_BLOB}${data.byteLength} `
386+
return header + data
387387
}
388388

389389
if (data === null || data === undefined) {

0 commit comments

Comments
 (0)