mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-22 08:38:29 +02:00
Environment data model backend
This commit is contained in:
5
.sqllsrc.json
Normal file
5
.sqllsrc.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"name": "yaak-dev",
|
||||||
|
"adapter": "sqlite3",
|
||||||
|
"filename": "src-tauri/db.sqlite"
|
||||||
|
}
|
||||||
15
src-tauri/migrations/20231022205109_environments.sql
Normal file
15
src-tauri/migrations/20231022205109_environments.sql
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
CREATE TABLE environments
|
||||||
|
(
|
||||||
|
id TEXT NOT NULL
|
||||||
|
PRIMARY KEY,
|
||||||
|
model TEXT DEFAULT 'workspace' NOT NULL,
|
||||||
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||||
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||||
|
deleted_at DATETIME,
|
||||||
|
workspace_id TEXT NOT NULL
|
||||||
|
REFERENCES workspaces
|
||||||
|
ON DELETE CASCADE,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
data TEXT NOT NULL
|
||||||
|
DEFAULT '{}'
|
||||||
|
);
|
||||||
@@ -398,6 +398,70 @@
|
|||||||
},
|
},
|
||||||
"query": "\n INSERT INTO http_responses (\n id,\n request_id,\n workspace_id,\n elapsed,\n url,\n status,\n status_reason,\n content_length,\n body,\n body_path,\n headers\n )\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);\n "
|
"query": "\n INSERT INTO http_responses (\n id,\n request_id,\n workspace_id,\n elapsed,\n url,\n status,\n status_reason,\n content_length,\n body,\n body_path,\n headers\n )\n VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);\n "
|
||||||
},
|
},
|
||||||
|
"986763e31599881f287ef378002fc35d8e983af10a30a9aa4ade606dacf83260": {
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"ordinal": 0,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "workspace_id",
|
||||||
|
"ordinal": 1,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "model",
|
||||||
|
"ordinal": 2,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "created_at",
|
||||||
|
"ordinal": 3,
|
||||||
|
"type_info": "Datetime"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "updated_at",
|
||||||
|
"ordinal": 4,
|
||||||
|
"type_info": "Datetime"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "name",
|
||||||
|
"ordinal": 5,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "data!: Json<HashMap<String, JsonValue>>",
|
||||||
|
"ordinal": 6,
|
||||||
|
"type_info": "Text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nullable": [
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"query": "\n SELECT id, workspace_id, model, created_at, updated_at, name,\n data AS \"data!: Json<HashMap<String, JsonValue>>\"\n FROM environments\n WHERE workspace_id = ?\n "
|
||||||
|
},
|
||||||
|
"ab7294b681f1202ef06aaa26885147ead2db6ac740023793cda1e1c92665d996": {
|
||||||
|
"describe": {
|
||||||
|
"columns": [],
|
||||||
|
"nullable": [],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 4
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"query": "\n INSERT INTO environments (\n id,\n workspace_id,\n name,\n data\n )\n VALUES (?, ?, ?, ?)\n "
|
||||||
|
},
|
||||||
"b19c275180909a39342b13c3cdcf993781636913ae590967f5508c46a56dc961": {
|
"b19c275180909a39342b13c3cdcf993781636913ae590967f5508c46a56dc961": {
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [],
|
"columns": [],
|
||||||
@@ -731,5 +795,59 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"query": "\n INSERT INTO workspaces (id, name, description)\n VALUES (?, ?, ?)\n "
|
"query": "\n INSERT INTO workspaces (id, name, description)\n VALUES (?, ?, ?)\n "
|
||||||
|
},
|
||||||
|
"fb89f653780b3f3ab0dd0bb2af30c8d3945203819cb9df7bdd331df56a6ae690": {
|
||||||
|
"describe": {
|
||||||
|
"columns": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"ordinal": 0,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "model",
|
||||||
|
"ordinal": 1,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "workspace_id",
|
||||||
|
"ordinal": 2,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "created_at",
|
||||||
|
"ordinal": 3,
|
||||||
|
"type_info": "Datetime"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "updated_at",
|
||||||
|
"ordinal": 4,
|
||||||
|
"type_info": "Datetime"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "name",
|
||||||
|
"ordinal": 5,
|
||||||
|
"type_info": "Text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "data!: Json<HashMap<String, JsonValue>>",
|
||||||
|
"ordinal": 6,
|
||||||
|
"type_info": "Text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nullable": [
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
"parameters": {
|
||||||
|
"Right": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"query": "\n SELECT\n id,\n model,\n workspace_id,\n created_at,\n updated_at,\n name,\n data AS \"data!: Json<HashMap<String, JsonValue>>\"\n FROM environments\n WHERE id = ?\n "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,18 @@ pub struct Workspace {
|
|||||||
pub description: String,
|
pub description: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(sqlx::FromRow, Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct Environment {
|
||||||
|
pub id: String,
|
||||||
|
pub workspace_id: String,
|
||||||
|
pub model: String,
|
||||||
|
pub created_at: NaiveDateTime,
|
||||||
|
pub updated_at: NaiveDateTime,
|
||||||
|
pub name: String,
|
||||||
|
pub data: Json<HashMap<String, JsonValue>>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct HttpRequestHeader {
|
pub struct HttpRequestHeader {
|
||||||
@@ -31,11 +43,11 @@ pub struct HttpRequestHeader {
|
|||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct HttpRequest {
|
pub struct HttpRequest {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
pub workspace_id: String,
|
||||||
pub model: String,
|
pub model: String,
|
||||||
pub created_at: NaiveDateTime,
|
pub created_at: NaiveDateTime,
|
||||||
pub updated_at: NaiveDateTime,
|
pub updated_at: NaiveDateTime,
|
||||||
pub sort_priority: f64,
|
pub sort_priority: f64,
|
||||||
pub workspace_id: String,
|
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub url: String,
|
pub url: String,
|
||||||
pub method: String,
|
pub method: String,
|
||||||
@@ -193,6 +205,74 @@ pub async fn create_workspace(
|
|||||||
get_workspace(&id, pool).await
|
get_workspace(&id, pool).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn find_environments(
|
||||||
|
workspace_id: &str,
|
||||||
|
pool: &Pool<Sqlite>,
|
||||||
|
) -> Result<Vec<Environment>, sqlx::Error> {
|
||||||
|
sqlx::query_as!(
|
||||||
|
Environment,
|
||||||
|
r#"
|
||||||
|
SELECT id, workspace_id, model, created_at, updated_at, name,
|
||||||
|
data AS "data!: Json<HashMap<String, JsonValue>>"
|
||||||
|
FROM environments
|
||||||
|
WHERE workspace_id = ?
|
||||||
|
"#,
|
||||||
|
workspace_id,
|
||||||
|
)
|
||||||
|
.fetch_all(pool)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn create_environment(
|
||||||
|
workspace_id: &str,
|
||||||
|
name: &str,
|
||||||
|
data: HashMap<String, JsonValue>,
|
||||||
|
pool: &Pool<Sqlite>,
|
||||||
|
) -> Result<Environment, sqlx::Error> {
|
||||||
|
let id = generate_id(Some("en"));
|
||||||
|
let data_json = Json(data);
|
||||||
|
let trimmed_name = name.trim();
|
||||||
|
sqlx::query!(
|
||||||
|
r#"
|
||||||
|
INSERT INTO environments (
|
||||||
|
id,
|
||||||
|
workspace_id,
|
||||||
|
name,
|
||||||
|
data
|
||||||
|
)
|
||||||
|
VALUES (?, ?, ?, ?)
|
||||||
|
"#,
|
||||||
|
id,
|
||||||
|
workspace_id,
|
||||||
|
trimmed_name,
|
||||||
|
data_json,
|
||||||
|
)
|
||||||
|
.execute(pool)
|
||||||
|
.await?;
|
||||||
|
get_environment(&id, pool).await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_environment(id: &str, pool: &Pool<Sqlite>) -> Result<Environment, sqlx::Error> {
|
||||||
|
sqlx::query_as!(
|
||||||
|
Environment,
|
||||||
|
r#"
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
model,
|
||||||
|
workspace_id,
|
||||||
|
created_at,
|
||||||
|
updated_at,
|
||||||
|
name,
|
||||||
|
data AS "data!: Json<HashMap<String, JsonValue>>"
|
||||||
|
FROM environments
|
||||||
|
WHERE id = ?
|
||||||
|
"#,
|
||||||
|
id,
|
||||||
|
)
|
||||||
|
.fetch_one(pool)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn duplicate_request(id: &str, pool: &Pool<Sqlite>) -> Result<HttpRequest, sqlx::Error> {
|
pub async fn duplicate_request(id: &str, pool: &Pool<Sqlite>) -> Result<HttpRequest, sqlx::Error> {
|
||||||
let existing = get_request(id, pool).await?;
|
let existing = get_request(id, pool).await?;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import { RecentRequestsDropdown } from './RecentRequestsDropdown';
|
|||||||
import { RequestActionsDropdown } from './RequestActionsDropdown';
|
import { RequestActionsDropdown } from './RequestActionsDropdown';
|
||||||
import { SidebarActions } from './SidebarActions';
|
import { SidebarActions } from './SidebarActions';
|
||||||
import { WorkspaceActionsDropdown } from './WorkspaceActionsDropdown';
|
import { WorkspaceActionsDropdown } from './WorkspaceActionsDropdown';
|
||||||
|
import { Button } from './core/Button';
|
||||||
|
import { useDialog } from './DialogContext';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
className?: string;
|
className?: string;
|
||||||
@@ -14,6 +16,7 @@ interface Props {
|
|||||||
|
|
||||||
export const WorkspaceHeader = memo(function WorkspaceHeader({ className }: Props) {
|
export const WorkspaceHeader = memo(function WorkspaceHeader({ className }: Props) {
|
||||||
const activeRequest = useActiveRequest();
|
const activeRequest = useActiveRequest();
|
||||||
|
const dialog = useDialog();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<HStack
|
<HStack
|
||||||
@@ -24,6 +27,14 @@ export const WorkspaceHeader = memo(function WorkspaceHeader({ className }: Prop
|
|||||||
<HStack space={0.5} className="flex-1 pointer-events-none" alignItems="center">
|
<HStack space={0.5} className="flex-1 pointer-events-none" alignItems="center">
|
||||||
<SidebarActions />
|
<SidebarActions />
|
||||||
<WorkspaceActionsDropdown className="pointer-events-auto" />
|
<WorkspaceActionsDropdown className="pointer-events-auto" />
|
||||||
|
<Button onClick={() => {
|
||||||
|
dialog.show({
|
||||||
|
title: 'Testing',
|
||||||
|
render: () => <div>These are THE environments</div>
|
||||||
|
})
|
||||||
|
}}>
|
||||||
|
Environments
|
||||||
|
</Button>
|
||||||
</HStack>
|
</HStack>
|
||||||
<div className="pointer-events-none">
|
<div className="pointer-events-none">
|
||||||
<RecentRequestsDropdown />
|
<RecentRequestsDropdown />
|
||||||
|
|||||||
Reference in New Issue
Block a user