Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Henus321 committed Aug 21, 2024
1 parent 71e71b3 commit 19cf7f9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
30 changes: 15 additions & 15 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ export default function App() {
const baseName = defaultBasePrefix + '-' + defaultBasePostfix;

useEffect(() => {
const loadBase = async (): Promise<void> => {
setPath((await getDatabasePath(baseName)) || "can't find path");

// инициализирую подключение к базе
try {
await DB.open(baseName);
setOpened(true);
} catch (error: any) {
Alert.alert(
'Внимание',
'Не удалось открыть базу данных: ' + error.message
);
}
};

loadBase();
}, []);

const loadBase = async (): Promise<void> => {
setPath((await getDatabasePath(baseName)) || "can't find path");

// инициализирую подключение к базе
try {
await DB.open(baseName);
setOpened(true);
} catch (error: any) {
Alert.alert(
'Внимание',
'Не удалось открыть базу данных: ' + error.message
);
}
};

return (
<View style={styles.container}>
{opened ? (
Expand Down
34 changes: 17 additions & 17 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@ const SQLiteExplorer = ({ params }: SQLiteExplorerProps) => {
const [select, setSelect] = useState('');

useEffect(() => {
const loadBase = async () => {
try {
await DB.open(params);
setSignatures(
((await DB.getTablesSignature()) || []).sort((a, b) =>
a.name.localeCompare(b.name)
)
);
} catch (error: any) {
Alert.alert(
'Внимание',
'Не удалось открыть базу данных: ' + error.message
);
}
};

loadBase();
}, []);

Expand All @@ -41,7 +25,23 @@ const SQLiteExplorer = ({ params }: SQLiteExplorerProps) => {
signatures.find((signature) => signature.name === select) || null;

if (!!curSignature) queryTableData(curSignature);
}, [select, signatures]);
}, [select]);

const loadBase = async () => {
try {
await DB.open(params);
setSignatures(
((await DB.getTablesSignature()) || []).sort((a, b) =>
a.name.localeCompare(b.name)
)
);
} catch (error: any) {
Alert.alert(
'Внимание',
'Не удалось открыть базу данных: ' + error.message
);
}
};

const queryTableData = async (signature: TableSignature) => {
if (!signature) return;
Expand Down

0 comments on commit 19cf7f9

Please sign in to comment.