-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d45d17
commit e93adb6
Showing
11 changed files
with
171 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
src/modules/editor/data/store.ts → src/modules/editor/data/resultStore.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { createStore, useStore } from "@/core/store"; | ||
|
||
export type SqlState = { | ||
saved: { | ||
id: string; | ||
name: string; | ||
query: string; | ||
}[]; | ||
}; | ||
|
||
export const sqlStore = createStore<SqlState>({ | ||
saved: [ | ||
{ | ||
id: "1", | ||
name: "Select Books", | ||
query: "SELECT * FROM books;", | ||
}, | ||
{ | ||
id: "2", | ||
name: "Select Authors", | ||
query: "SELECT * FROM authors;", | ||
}, | ||
{ | ||
id: "3", | ||
name: "Insert Authors", | ||
query: "Insert into authors (first_name,last_name) values ('Madhu','R');", | ||
}, | ||
], | ||
}); | ||
|
||
export const useSqlStore = () => { | ||
return useStore<SqlState>(sqlStore); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import alasql from "alasql"; | ||
|
||
import { tableSchemas } from "@/db/seed"; | ||
|
||
type SchemaState = { | ||
columns: { | ||
columnid: string; | ||
dbtypeid: string; | ||
}[]; | ||
table: { | ||
tableid: string; | ||
}; | ||
}; | ||
|
||
type Result = ReturnType<typeof alasql.parse> & { | ||
statements: SchemaState[]; | ||
}; | ||
|
||
export const useSchema = () => { | ||
const result = alasql.parse(tableSchemas.create.join(";")) as Result; | ||
|
||
const state = result.statements as SchemaState[]; | ||
|
||
return state; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useSetResultStore } from "../data/resultStore"; | ||
import { useSqlStore } from "../data/sqlStore"; | ||
|
||
const SavedQueries = () => { | ||
const [state] = useSqlStore(); | ||
const setResultState = useSetResultStore(); | ||
|
||
return ( | ||
<div> | ||
{state.saved.map((query) => ( | ||
<div | ||
key={query.id} | ||
className=" px-4 py-4 border-b cursor-pointer hover:bg-muted last:border-b-0" | ||
onClick={() => { | ||
setResultState({ | ||
pendingQuery: query.query, | ||
queryName: query.name, | ||
}); | ||
|
||
const event = new CustomEvent("query", { | ||
detail: { | ||
pendingQuery: query.query, | ||
queryName: query.name, | ||
}, | ||
}); | ||
|
||
window.dispatchEvent(event); | ||
}} | ||
> | ||
{query.name} | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default SavedQueries; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useSchema } from "../data/useSchema"; | ||
|
||
const SchemaTable = () => { | ||
const statements = useSchema(); | ||
|
||
return ( | ||
<div className="p-5"> | ||
{statements.map((statement) => { | ||
return ( | ||
<div key={statement.table.tableid}> | ||
<details className="mb-4"> | ||
<summary className="font-medium cursor-pointer"> | ||
{statement.table.tableid} | ||
</summary> | ||
<ul className="px-4"> | ||
{statement.columns.map((column) => { | ||
return ( | ||
<li | ||
key={column.columnid} | ||
className="flex justify-between items-center" | ||
> | ||
<span className="text-neutral-500"> | ||
{column.columnid} | ||
</span> | ||
<span className="text-neutral-500"> | ||
{column.dbtypeid} | ||
</span> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
</details> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
}; | ||
|
||
export default SchemaTable; |