Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit 43685e2

Browse files
committed
sql execute + fixing
1 parent f015460 commit 43685e2

File tree

10 files changed

+211
-314
lines changed

10 files changed

+211
-314
lines changed

README.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,42 @@
11
SQLite Viewer GUI Program written in Rust using Tauri + NextJS
22

3-
( TODO )
4-
- [ ] Add linux and macos Builds
3+
[ TODO LIST ]
4+
5+
- [ ] Make a web version ( if possible )
6+
- [ ] Add Linux and MacOS Builds
57
- [ ] Render performance for big sqlite files
6-
- [ ] Execute SQL command tab
8+
- [x] Execute SQL command tab
79
- [ ] Schema Generator
10+
- [ ] Sort by column
811
- [ ] Add themes
912

1013
##
1114

15+
### Features
16+
17+
**1- Browse All Your SQLite Tables.**
18+
19+
![photo](https://i.ibb.co/SBzVnFX/Browse.png)
20+
21+
**2- Database Structure View.**
22+
23+
![photo](https://i.ibb.co/8zGSBHN/Struct.png)
24+
25+
**3- Execute SQL Commands**
26+
27+
![photo](https://i.ibb.co/SnTXqwy/execute.png)
28+
29+
**4- Errors are easy to recognize**
30+
31+
![photo](https://i.ibb.co/Xtb0pZT/error.png)
32+
33+
##
34+
1235
1. **Clone the Repository**
1336

1437
```sh
15-
git clone https://github.com/TeaByte/sqlite-viewer.git
16-
cd sqlite-viewer
38+
git clone https://github.com/TeaByte/mt-uploader.git
39+
cd mt-uploader
1740
```
1841

1942
2. **Install Dependencies**
@@ -30,5 +53,3 @@ SQLite Viewer GUI Program written in Rust using Tauri + NextJS
3053
```
3154

3255
##
33-
34-
![photo](https://imgtr.ee/images/2023/09/28/03a88aef88d52e28852a7ec3db4e0cab.jpeg)

app/execute.tsx

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
"use client";
2+
3+
import { TableInfos } from "@/types";
4+
import {
5+
Table,
6+
TableBody,
7+
TableCell,
8+
TableHead,
9+
TableHeader,
10+
TableRow,
11+
} from "@/components/ui/table";
12+
import {
13+
Accordion,
14+
AccordionContent,
15+
AccordionItem,
16+
AccordionTrigger,
17+
} from "@/components/ui/accordion";
18+
19+
import { Textarea } from "@/components/ui/textarea";
20+
21+
import { invoke } from "@tauri-apps/api/tauri";
22+
import React, { useState } from "react";
23+
24+
type x =
25+
| { result: { Ok: Array<{ [key: string]: string }> } }
26+
| { result: { Err: string } };
27+
28+
export default function ExecuteSQL({ table }: { table: string }) {
29+
const [sql, setSQL] = useState("");
30+
const [result, setResult] = useState<string | string[]>();
31+
32+
async function executeSQLCall(e: React.FormEvent<HTMLFormElement>) {
33+
e.preventDefault();
34+
if (sql.length === 0) {
35+
setResult("No SQL to execute");
36+
return;
37+
}
38+
const executeResult = await invoke<any>("execute", {
39+
sql: sql,
40+
});
41+
42+
console.log(executeResult);
43+
44+
if (executeResult.result.Err) {
45+
setResult(executeResult.result.Err);
46+
return;
47+
}
48+
49+
if (executeResult.result.Ok.length === 0) {
50+
setResult("SQL Executed successfully with no results");
51+
return;
52+
}
53+
54+
setResult(executeResult.result.Ok);
55+
}
56+
57+
return (
58+
<div className="flex flex-col">
59+
<form onSubmit={executeSQLCall} className="px-4 flex flex-col gap-2">
60+
<Textarea
61+
placeholder={`SELECT * FROM ${table}`}
62+
value={sql}
63+
onChange={(e) => setSQL(e.target.value)}
64+
/>
65+
<button className="bg-secondary text-primary p-2 px-10 rounded-md hover:bg-primary hover:text-secondary transition-all">
66+
Execute SQL
67+
</button>
68+
{typeof result === "string" ? (
69+
<p>{result}</p>
70+
) : result instanceof Array ? (
71+
<table className="table-auto">
72+
<thead>
73+
<tr>
74+
{Object.keys(result[0]).map((key) => (
75+
<th key={key} className="border px-4 py-2">
76+
{key}
77+
</th>
78+
))}
79+
</tr>
80+
</thead>
81+
<tbody>
82+
{result.map((row, index) => (
83+
<tr key={index}>
84+
{Object.values(row).map((value, index) => (
85+
<td key={index} className="border px-4 py-2">
86+
{value}
87+
</td>
88+
))}
89+
</tr>
90+
))}
91+
</tbody>
92+
</table>
93+
) : null}
94+
</form>
95+
</div>
96+
);
97+
}

app/load.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { useState, useEffect } from "react";
55

66
import { invoke } from "@tauri-apps/api/tauri";
77
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
8+
89
import Browse from "./browse";
910
import Structure from "./structure";
11+
import ExecuteSQL from "./execute";
1012

1113
export default function Load({ path }: { path: string }) {
1214
const [records, setRecords] = useState<Columns>({});
@@ -82,7 +84,7 @@ export default function Load({ path }: { path: string }) {
8284
/>
8385
</TabsContent>
8486
<TabsContent value="execute">
85-
<h1>Not implemented yet!</h1>
87+
<ExecuteSQL table={tables[0]} />
8688
</TabsContent>
8789
</Tabs>
8890
</div>

app/page.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,17 @@ export default function Home() {
3333
{selectedDataBase ? (
3434
<Load path={selectedDataBase} />
3535
) : (
36-
<button className="p-4 bg-primary text-background" onClick={onClick}>
37-
Select Database
38-
</button>
36+
<div className="flex flex-col mt-20 gap-2 text-center">
37+
<h1 className="text-center text-5xl">SQLite Viewer</h1>
38+
<button
39+
className="p-4 bg-primary text-background w-full hover:opacity-80"
40+
onClick={onClick}
41+
>
42+
Select Database
43+
</button>
44+
<p>SQLite Viewer GUI Program written in Rust using Tauri + NextJS</p>
45+
<p>I dont know what to put in this place!</p>
46+
</div>
3947
)}
4048
</main>
4149
);

components/ui/button.tsx

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

0 commit comments

Comments
 (0)