Skip to content

Commit e8b4f42

Browse files
author
Oscar Franco
committed
Change executeSql definition to fail when status equals 1
1 parent 94f618c commit e8b4f42

3 files changed

Lines changed: 30 additions & 12 deletions

File tree

example/src/App.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import {
1717
testTransaction,
1818
typeORMGetBooks,
1919
typeORMInit,
20+
executeFailingTypeORMQuery,
2021
} from './Database';
21-
// import { typeORMInit } from './Database';
2222
import type { User } from './model/User';
2323
import { Buffer } from 'buffer';
2424

@@ -30,11 +30,9 @@ export default function App() {
3030
// const users = queryUsers();
3131
// setUsers(users);
3232
typeORMInit().then(() => {
33-
console.warn('db initialized');
3433
typeORMGetBooks().then((books) => {
35-
console.warn('typeORM books', books);
36-
37-
})
34+
// console.warn('typeORM books', books);
35+
});
3836
});
3937
}, []);
4038

@@ -62,6 +60,10 @@ export default function App() {
6260
testTransaction();
6361
}}
6462
/>
63+
<Button
64+
title="Execute typeORM failing query"
65+
onPress={executeFailingTypeORMQuery}
66+
/>
6567
<FlatList
6668
data={users}
6769
renderItem={({ item }: ListRenderItemInfo<User>) => {

example/src/Database.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { DataSource } from 'typeorm';
44
import { Book } from './model/Book';
55
import { User } from './model/User';
66
// import { Buffer } from 'buffer';
7-
let datasource: DataSource
7+
let datasource: DataSource;
88

99
export const lowLevelInit = () => {
1010
// Start by opening a connection
@@ -86,11 +86,10 @@ export async function typeORMInit() {
8686
database: 'test2',
8787
location: '.',
8888
entities: [Book],
89-
synchronize: true
89+
synchronize: true,
9090
});
9191

92-
await datasource.initialize()
93-
92+
await datasource.initialize();
9493

9594
// await createConnection({
9695
// type: 'react-native',
@@ -129,5 +128,17 @@ export async function typeORMInit() {
129128

130129
export async function typeORMGetBooks() {
131130
const bookRepository = datasource.getRepository(Book);
132-
return await bookRepository.find()
133-
}
131+
return await bookRepository.find();
132+
}
133+
134+
export async function executeFailingTypeORMQuery() {
135+
const bookRepository = datasource.getRepository(Book);
136+
137+
try {
138+
const manualQuery = await bookRepository.query(`
139+
SELECT * From UnexistingTable
140+
`);
141+
} catch (e) {
142+
console.warn('should have cached');
143+
}
144+
}

src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,12 @@ export const openDatabase = (
359359
try {
360360
let response = sqlite.executeSql(options.name, sql, params);
361361
enhanceQueryResult(response);
362-
ok(response);
362+
363+
if (response.status === 1) {
364+
fail(response.message);
365+
} else {
366+
ok(response);
367+
}
363368
} catch (e) {
364369
fail(e);
365370
}

0 commit comments

Comments
 (0)