Skip to content

Commit

Permalink
Typescript fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ospfranco committed Oct 31, 2024
1 parent 0b9f28d commit 662ba2e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
10 changes: 5 additions & 5 deletions example/src/tests/blob.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function blobTests() {

const result = await db.execute('SELECT content FROM BlobTable');

const finalUint8 = new Uint8Array(result.rows?.[0].content);
const finalUint8 = new Uint8Array(result.rows[0]!.content as any);
expect(finalUint8[0]).to.equal(42);
});

Expand All @@ -63,7 +63,7 @@ export function blobTests() {

const result = await db.execute('SELECT content FROM BlobTable');

const finalUint8 = new Uint8Array(result.rows?.[0].content);
const finalUint8 = new Uint8Array(result.rows[0]!.content as any);
expect(finalUint8[0]).to.equal(42);
});

Expand All @@ -78,7 +78,7 @@ export function blobTests() {

const result = await db.execute('SELECT content FROM BlobTable');

const finalUint8 = new Uint8Array(result.rows?.[0].content);
const finalUint8 = new Uint8Array(result.rows[0]!.content as any);
expect(finalUint8[0]).to.equal(42);
});

Expand All @@ -95,7 +95,7 @@ export function blobTests() {

const result = await db.execute('SELECT content FROM BlobTable');

const finalUint8 = new Uint8Array(result.rows?.[0].content);
const finalUint8 = new Uint8Array(result.rows[0]!.content as any);
expect(finalUint8[0]).to.equal(46);
});

Expand All @@ -112,7 +112,7 @@ export function blobTests() {

const result = await db.execute('SELECT content FROM BlobTable');

const finalUint8 = new Uint8Array(result.rows?.[0].content);
const finalUint8 = new Uint8Array(result.rows[0]!.content as any);
expect(finalUint8[0]).to.equal(52);
});
});
Expand Down
2 changes: 1 addition & 1 deletion example/src/tests/dbsetup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function dbSetupTests() {

const res = await db.execute('select sqlite_version();');

expect(res.rows?.[0]['sqlite_version()']).to.equal(expectedVersion);
expect(res.rows[0]!['sqlite_version()']).to.equal(expectedVersion);
db.close();
});

Expand Down
6 changes: 3 additions & 3 deletions example/src/tests/preparedStatements.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ export function preparedStatementsTests() {
expect(results.rows?.length).to.equal(3);
results = await statement.execute();

expect(results.rows?.length).to.equal(3);
expect(results.rows.length).to.equal(3);
});

it('prepared statement, rebind select', async () => {
const statement = db.prepareStatement('SELECT * FROM User WHERE id = ?;');
statement.bind([1]);

let results = await statement.execute();
expect(results.rows?.[0].name === 'Oscar');
expect(results.rows[0]!.name === 'Oscar');

statement.bind([2]);
results = await statement.execute();
expect(results.rows?.[0].name === 'Pablo');
expect(results.rows[0]!.name === 'Pablo');
});

it('prepared statement, rebind insert', async () => {
Expand Down
20 changes: 10 additions & 10 deletions example/src/tests/queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export function queriesTests() {
const sumRes = await db.execute('SELECT SUM(age) as sum FROM User;');

// expect(sumRes.metadata?.[0]?.type).to.equal('UNKNOWN');
expect(sumRes.rows?.[0].sum).to.equal(age + age2);
expect(sumRes.rows[0]!.sum).to.equal(age + age2);

// MAX(networth), MIN(networth)
const maxRes = await db.execute(
Expand All @@ -218,8 +218,8 @@ export function queriesTests() {
const maxNetworth = Math.max(networth, networth2);
const minNetworth = Math.min(networth, networth2);

expect(maxRes.rows?.[0].max).to.equal(maxNetworth);
expect(minRes.rows?.[0].min).to.equal(minNetworth);
expect(maxRes.rows[0]!.max).to.equal(maxNetworth);
expect(minRes.rows[0]!.min).to.equal(minNetworth);
});

it('Executes all the statements in a single string', async () => {
Expand All @@ -235,13 +235,13 @@ export function queriesTests() {
"SELECT name FROM sqlite_master WHERE type='table' AND name='T1';",
);

expect(t1name.rows?.[0].name).to.equal('T1');
expect(t1name.rows[0]!.name).to.equal('T1');

let t2name = await db.execute(
"SELECT name FROM sqlite_master WHERE type='table' AND name='T2';",
);

expect(t2name.rows?.[0].name).to.equal('T2');
expect(t2name.rows[0]!.name).to.equal('T2');
});

it('Failed insert', async () => {
Expand Down Expand Up @@ -360,7 +360,7 @@ export function queriesTests() {
[id],
);

actual.push(results.rows?.[0].networth);
actual.push(results.rows[0]!.networth);
});

promises.push(promised);
Expand Down Expand Up @@ -583,9 +583,9 @@ export function queriesTests() {
},
]);

res.rows![0].name = 'quack_changed';
res.rows[0]!.name = 'quack_changed';

expect(res.rows![0].name).to.eq('quack_changed');
expect(res.rows[0]!.name).to.eq('quack_changed');
});

it('DumbHostObject allows to write new props', async () => {
Expand All @@ -612,9 +612,9 @@ export function queriesTests() {
},
]);

res.rows![0].myWeirdProp = 'quack_changed';
res.rows[0]!.myWeirdProp = 'quack_changed';

expect(res.rows![0].myWeirdProp).to.eq('quack_changed');
expect(res.rows[0]!.myWeirdProp).to.eq('quack_changed');
});

it('Execute raw should return just an array of objects', async () => {
Expand Down
2 changes: 1 addition & 1 deletion example/src/tests/reactive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function reactiveTests() {
table: 'User',
},
],
callback: data => {
callback: _data => {
fullSelectRan = true;
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export type QueryResult = {
insertId?: number;
rowsAffected: number;
res?: any[];
rows: any[];
rows: Array<Record<string, string | number | boolean | ArrayBufferLike>>;
// An array of intermediate results, just values without column names
rawRows?: any[];
columnNames?: string[];
Expand Down

0 comments on commit 662ba2e

Please sign in to comment.