Skip to content

Commit

Permalink
fix: make some fields optional
Browse files Browse the repository at this point in the history
  • Loading branch information
frectonz committed Jun 20, 2024
1 parent f30dde7 commit e7a0bdf
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 38 deletions.
19 changes: 8 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ mod sqlite {

Ok(responses::Overview {
file_name,
sqlite_version,
sqlite_version: Some(sqlite_version),
file_size,
created,
modified,
Expand Down Expand Up @@ -443,7 +443,7 @@ mod sqlite {

Ok(responses::Table {
name,
sql,
sql: Some(sql),
row_count,
table_size,
index_count,
Expand Down Expand Up @@ -689,7 +689,7 @@ mod libsql {

Ok(responses::Overview {
file_name,
sqlite_version,
sqlite_version: Some(sqlite_version),
file_size,
created,
modified,
Expand Down Expand Up @@ -816,7 +816,7 @@ mod libsql {

Ok(responses::Table {
name,
sql,
sql: Some(sql),
row_count,
table_size,
index_count,
Expand Down Expand Up @@ -996,7 +996,6 @@ mod postgres {
.await?
.get(0);

let sqlite_version = "---".to_owned();
let file_size: i64 = self
.client
.query_one("SELECT pg_database_size($1)", &[&file_name])
Expand Down Expand Up @@ -1082,7 +1081,7 @@ mod postgres {

Ok(responses::Overview {
file_name,
sqlite_version,
sqlite_version: None,
file_size,
created,
modified,
Expand Down Expand Up @@ -1119,8 +1118,6 @@ mod postgres {
}

async fn table(&self, name: String) -> color_eyre::Result<responses::Table> {
let sql = "".to_owned();

let row_count: i64 = self
.client
.query_one(&format!(r#"SELECT count(*) FROM "{name}""#), &[])
Expand Down Expand Up @@ -1163,7 +1160,7 @@ mod postgres {

Ok(responses::Table {
name,
sql,
sql: None,
row_count: row_count as i32,
table_size,
index_count: index_count as i32,
Expand Down Expand Up @@ -1316,8 +1313,8 @@ mod responses {
#[derive(Serialize)]
pub struct Overview {
pub file_name: String,
pub sqlite_version: String,
pub file_size: String,
pub sqlite_version: Option<String>,
pub created: Option<DateTime<Utc>>,
pub modified: Option<DateTime<Utc>>,
pub tables: i32,
Expand All @@ -1341,7 +1338,7 @@ mod responses {
#[derive(Serialize)]
pub struct Table {
pub name: String,
pub sql: String,
pub sql: Option<String>,
pub row_count: i32,
pub index_count: i32,
pub column_count: i32,
Expand Down
4 changes: 2 additions & 2 deletions ui/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const BASE_URL = import.meta.env.PROD ? "/api" : "http://localhost:3030/api";

const overview = z.object({
file_name: z.string(),
sqlite_version: z.string(),
sqlite_version: z.string().nullable(),
file_size: z.string(),
created: z
.string()
Expand Down Expand Up @@ -40,7 +40,7 @@ const tables = z.object({

const table = z.object({
name: z.string(),
sql: z.string(),
sql: z.string().nullable(),
row_count: z.number(),
index_count: z.number(),
column_count: z.number(),
Expand Down
24 changes: 13 additions & 11 deletions ui/src/routes/index.lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,19 @@ function Index() {
<TableCell className="text-right">{data.file_size}</TableCell>
</TableRow>

<TableRow>
<TableCell>
<div className="font-medium">SQLite version</div>
<div className="text-sm text-muted-foreground md:inline">
The SQLite version the DB was created with.
</div>
</TableCell>
<TableCell className="text-right">
{data.sqlite_version}
</TableCell>
</TableRow>
{data.sqlite_version && (
<TableRow>
<TableCell>
<div className="font-medium">SQLite version</div>
<div className="text-sm text-muted-foreground md:inline">
The SQLite version the DB was created with.
</div>
</TableCell>
<TableCell className="text-right">
{data.sqlite_version}
</TableCell>
</TableRow>
)}

{data.created && (
<TableRow>
Expand Down
30 changes: 16 additions & 14 deletions ui/src/routes/tables.lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,22 @@ function Table({ name }: Props) {
</Card>
</div>

<Card className="font-mono text-sm">
<CodeBlock
text={data.sql}
language="sql"
theme={currentTheme === "dark" ? CodeDarkTheme : undefined}
showLineNumbers={false}
customStyle={{
FontFace: "JetBrains Mono",
padding: "10px",
backgroundColor: currentTheme === "dark" ? "#091813" : "#f5faf9",
borderRadius: "10px",
}}
/>
</Card>
{data.sql && (
<Card className="font-mono text-sm">
<CodeBlock
text={data.sql}
language="sql"
theme={currentTheme === "dark" ? CodeDarkTheme : undefined}
showLineNumbers={false}
customStyle={{
FontFace: "JetBrains Mono",
padding: "10px",
backgroundColor: currentTheme === "dark" ? "#091813" : "#f5faf9",
borderRadius: "10px",
}}
/>
</Card>
)}

<TableData name={data.name} />
</div>
Expand Down

0 comments on commit e7a0bdf

Please sign in to comment.