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

Commit e799142

Browse files
committed
fixing
1 parent a9afa64 commit e799142

File tree

10 files changed

+85
-91
lines changed

10 files changed

+85
-91
lines changed

README.md

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
1-
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
1+
SQLite Viewer GUI Program written in Rust using Tauri + NextJS
22

3-
## Getting Started
3+
( TODO )
44

5-
First, run the development server:
5+
- [ ] Render performance for big sqlite files
6+
- [ ] Execute SQL command tab
7+
- [ ] Add themes
68

7-
```bash
8-
npm run dev
9-
# or
10-
yarn dev
11-
# or
12-
pnpm dev
13-
# or
14-
bun dev
15-
```
9+
##
1610

17-
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
11+
1. **Clone the Repository**
1812

19-
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
13+
```sh
14+
git clone https://github.com/TeaByte/mt-uploader.git
15+
cd mt-uploader
16+
```
2017

21-
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
18+
2. **Install Dependencies**
2219

23-
## Learn More
20+
```sh
21+
npm install
22+
cargo install tauri-cli
23+
```
2424

25-
To learn more about Next.js, take a look at the following resources:
25+
3. **Start Dev Server**
2626

27-
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28-
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
27+
```sh
28+
cargo tauri dev
29+
```
2930

30-
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
31-
32-
## Deploy on Vercel
33-
34-
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
35-
36-
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
31+
![photo](https://srv2.imgonline.com.ua/result_img/imgonline-com-ua-twotoone-77HXRnGZ6H1cqsD1.jpg)

app/browse.tsx

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,26 @@ export default function Browse(props: BrowseProps) {
3232
return (
3333
<div className="w-full">
3434
<div className="px-2">
35-
<Select
36-
// value={tables[0]}
37-
onValueChange={(table: string) => setSelectedTable(table)}
38-
>
39-
<SelectTrigger className="w-[180px]">
40-
<SelectValue placeholder="Select Table" />
41-
</SelectTrigger>
42-
<SelectContent className="h-[150px] overflow-y-auto">
43-
<SelectGroup>
44-
<SelectLabel>Select Table</SelectLabel>
45-
{tables.map((table, index) => (
46-
<SelectItem value={table} key={index}>
47-
{table}
48-
</SelectItem>
49-
))}
50-
</SelectGroup>
51-
</SelectContent>
52-
</Select>
35+
{selectedTable && (
36+
<Select
37+
value={selectedTable}
38+
onValueChange={(table: string) => setSelectedTable(table)}
39+
>
40+
<SelectTrigger className="w-[180px]">
41+
<SelectValue placeholder="Select Table" />
42+
</SelectTrigger>
43+
<SelectContent className="h-[150px] overflow-y-auto">
44+
<SelectGroup>
45+
<SelectLabel>Select Table</SelectLabel>
46+
{tables.map((table, index) => (
47+
<SelectItem value={table} key={index}>
48+
{table}
49+
</SelectItem>
50+
))}
51+
</SelectGroup>
52+
</SelectContent>
53+
</Select>
54+
)}
5355
</div>
5456
<div className="mt-3 h-[420px] overflow-auto">
5557
{selectedTable && records[selectedTable] && (

app/load.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default function Load({ path }: { path: string }) {
8282
/>
8383
</TabsContent>
8484
<TabsContent value="execute">
85-
<h1>execute</h1>
85+
<h1>Not implemented yet!</h1>
8686
</TabsContent>
8787
</Tabs>
8888
</div>

app/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export default function Home() {
3333
{selectedDataBase ? (
3434
<Load path={selectedDataBase} />
3535
) : (
36-
<button className="p-2 bg-slate-500" onClick={onClick}>
37-
Upload
36+
<button className="p-4 bg-primary text-background" onClick={onClick}>
37+
Select Database
3838
</button>
3939
)}
4040
</main>

app/structure.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@ import {
1616
AccordionTrigger,
1717
} from "@/components/ui/accordion";
1818

19-
import { ArrowDownIcon } from "@radix-ui/react-icons";
20-
21-
interface StructureProps {
22-
tablesInfo: TableInfos;
23-
}
24-
25-
export default function Structure({ tablesInfo }: StructureProps) {
19+
export default function Structure({ tablesInfo }: { tablesInfo: TableInfos }) {
2620
return (
2721
<div className="w-full">
2822
<Accordion type="single" collapsible className="w-full">
@@ -32,7 +26,6 @@ export default function Structure({ tablesInfo }: StructureProps) {
3226
<AccordionTrigger className="font-bold p-2 bg-secondary opacity-70 flex gap-1 items-center">
3327
{table}
3428
</AccordionTrigger>
35-
3629
<AccordionContent>
3730
<Table>
3831
<TableHeader>

src-tauri/C

Whitespace-only changes.

src-tauri/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,4 @@ lazy_static = "1.4"
2222
rusqlite = { version = "0.29.0", features = ["bundled"] }
2323

2424
[features]
25-
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.
26-
# If you use cargo directly instead of tauri's cli you can use this feature flag to switch between tauri's `dev` and `build` modes.
27-
# DO NOT REMOVE!!
2825
custom-protocol = [ "tauri/custom-protocol" ]

src-tauri/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
fn main() {
2-
tauri_build::build()
2+
tauri_build::build()
33
}

src-tauri/src/database.rs

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use rusqlite::{Connection};
21
use rusqlite::types::Value;
2+
use rusqlite::Connection;
33
use serde::Serialize;
44

55
#[derive(Debug, Serialize)]
@@ -28,10 +28,11 @@ impl DataBase {
2828
}
2929

3030
pub fn get_tables(&self) -> Vec<String> {
31-
let mut stmt = self.connection
32-
.prepare("SELECT name FROM sqlite_master WHERE type='table'")
33-
.expect("Failed to prepare query");
34-
31+
let mut stmt = self
32+
.connection
33+
.prepare("SELECT name FROM sqlite_master WHERE type='table'")
34+
.expect("Failed to prepare query");
35+
3536
let tables_names: Vec<String> = stmt
3637
.query_map([], |row| Ok(row.get(0)?))
3738
.expect("Failed to get tables from database")
@@ -42,19 +43,22 @@ impl DataBase {
4243
}
4344

4445
pub fn get_table_info(&self, table_name: &String) -> Vec<TableInfo> {
45-
let mut stmt = self.connection
46+
let mut stmt = self
47+
.connection
4648
.prepare(&format!("PRAGMA table_info({})", table_name))
4749
.expect("Failed to prepare query");
4850

4951
let table_info: Vec<TableInfo> = stmt
50-
.query_map([], |row| Ok(TableInfo {
51-
cid: row.get(0)?,
52-
name: row.get(1)?,
53-
r#type: row.get(2)?,
54-
notnull: row.get(3)?,
55-
dflt_value: row.get(4)?,
56-
pk: row.get(5)?,
57-
}))
52+
.query_map([], |row| {
53+
Ok(TableInfo {
54+
cid: row.get(0)?,
55+
name: row.get(1)?,
56+
r#type: row.get(2)?,
57+
notnull: row.get(3)?,
58+
dflt_value: row.get(4)?,
59+
pk: row.get(5)?,
60+
})
61+
})
5862
.expect("Failed to get table info from database")
5963
.map(|result| result.unwrap())
6064
.collect();
@@ -64,24 +68,23 @@ impl DataBase {
6468

6569
pub fn get_column(&self, table_name: &str, column_name: &str) -> Vec<Value> {
6670
let mut stmt = self
67-
.connection
68-
.prepare(&format!("SELECT {} FROM {}", column_name, table_name))
69-
.expect("Failed to prepare fetch query");
71+
.connection
72+
.prepare(&format!("SELECT {} FROM {}", column_name, table_name))
73+
.expect("Failed to prepare fetch query");
7074

71-
let results: Vec<Value> = stmt
72-
.query_map([], |row| {
73-
let value = row.get(0)?;
74-
Ok(value)
75-
})
76-
.expect("Failed to execute query")
77-
.map(|result| result.unwrap())
78-
.collect();
75+
let results: Vec<Value> = stmt
76+
.query_map([], |row| {
77+
let value = row.get(0)?;
78+
Ok(value)
79+
})
80+
.expect("Failed to execute query")
81+
.map(|result| result.unwrap())
82+
.collect();
7983

80-
results
84+
results
8185
}
8286
}
8387

84-
8588
/// Convert Value to String
8689
pub fn convert(value: Value) -> String {
8790
match value {
@@ -91,4 +94,4 @@ pub fn convert(value: Value) -> String {
9194
Value::Text(v) => v.to_string(),
9295
Value::Blob(_) => String::from("Blob"),
9396
}
94-
}
97+
}

src-tauri/src/main.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
22

3-
use std::sync::Mutex;
43
use lazy_static::lazy_static;
4+
use std::sync::Mutex;
55

66
mod database;
7-
use database::{DataBase, convert, TableInfo};
7+
use database::{convert, DataBase, TableInfo};
88

99
lazy_static! {
1010
static ref DB_INSTANCE: Mutex<Option<DataBase>> = Mutex::new(None);
1111
}
1212

1313
fn main() {
1414
tauri::Builder::default()
15-
.invoke_handler(tauri::generate_handler![change_database_path, get_tables, get_table_info, get_column])
15+
.invoke_handler(tauri::generate_handler![
16+
change_database_path,
17+
get_tables,
18+
get_table_info,
19+
get_column
20+
])
1621
.run(tauri::generate_context!())
1722
.expect("error while running tauri application");
1823
}
1924

20-
2125
#[tauri::command]
2226
fn change_database_path(new_path: String) {
2327
*DB_INSTANCE.lock().unwrap() = Some(DataBase::new(&new_path));

0 commit comments

Comments
 (0)