db-studio 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -0
- package/dist/core-dist/assets/_pathlessLayout-B3hOmNOY.js +1 -0
- package/dist/core-dist/assets/_queryId-B-Yx8vY8.js +1 -0
- package/dist/core-dist/assets/{_table-7G_H-EMC.js → _table-C9ZV09Jc.js} +1 -1
- package/dist/core-dist/assets/_table-DIbBLMgY.js +39 -0
- package/dist/core-dist/assets/{cdoe-editor-CsnVz62S.js → cdoe-editor-BUyGnaMR.js} +1 -1
- package/dist/core-dist/assets/{dialog-C7B5v45l.js → dialog-BtqI2R7E.js} +1 -1
- package/dist/core-dist/assets/icons-B2mES2Qq.js +1 -0
- package/dist/core-dist/assets/index-BV7euJxs.js +1 -0
- package/dist/core-dist/assets/{index-BKJZ_DtH.js → index-C7KJNEv-.js} +1 -1
- package/dist/core-dist/assets/index-CESnXcY7.js +1 -0
- package/dist/core-dist/assets/index-CTFnCamQ.js +1 -0
- package/dist/core-dist/assets/index-DO_12lzR.js +58 -0
- package/dist/core-dist/assets/index-DQOVykiS.js +1 -0
- package/dist/core-dist/assets/{indexes-chzZ9aUc.js → indexes-DESnDRwn.js} +1 -1
- package/dist/core-dist/assets/logs-DKdQRaOz.js +1 -0
- package/dist/core-dist/assets/{queries.store-kf8rwRRK.js → queries.store-DCqn9r_M.js} +1 -1
- package/dist/core-dist/assets/{radix-ui-DdSZPsGt.js → radix-ui-c-7GrHMM.js} +1 -1
- package/dist/core-dist/assets/{react-dom-CFlhbIUR.js → react-dom-BcUZDRtY.js} +1 -1
- package/dist/core-dist/assets/runner-tab-CloOoJUy.js +3 -0
- package/dist/core-dist/assets/{scroll-area-CGOQphQG.js → scroll-area-D613A-kL.js} +1 -1
- package/dist/core-dist/assets/{tanstack-VIQ5XZ7a.js → tanstack-BaWakKkc.js} +1 -1
- package/dist/core-dist/assets/{tooltip-eBZ2rltH.js → tooltip-B4cd0H8Q.js} +1 -1
- package/dist/core-dist/assets/{use-delete-column-CqTA9IkF.js → use-delete-column-DxoXObaz.js} +1 -1
- package/dist/core-dist/assets/{visualizer-CW4V7-VL.js → visualizer-CQGMZpWZ.js} +1 -1
- package/dist/core-dist/index.html +5 -5
- package/dist/index.js +12 -12
- package/dist/index.js.map +1 -1
- package/package.json +14 -14
- package/dist/core-dist/assets/_pathlessLayout-BSFx2CpL.js +0 -1
- package/dist/core-dist/assets/_queryId-CgXpSMOd.js +0 -1
- package/dist/core-dist/assets/_table-BD8P3EpN.js +0 -39
- package/dist/core-dist/assets/icons-BTbp9JOE.js +0 -1
- package/dist/core-dist/assets/index-BbUfG55J.js +0 -1
- package/dist/core-dist/assets/index-C0XbK31u.js +0 -58
- package/dist/core-dist/assets/index-CywuOneB.js +0 -1
- package/dist/core-dist/assets/index-CzPkrj7Y.js +0 -1
- package/dist/core-dist/assets/index-DpF8uPY5.js +0 -1
- package/dist/core-dist/assets/logs-BC5WPG0r.js +0 -1
- package/dist/core-dist/assets/runner-tab-D2PzASo9.js +0 -3
package/README.md
CHANGED
|
@@ -23,3 +23,47 @@ A modern, universal (pgAdmin alternative) database management studio for any dat
|
|
|
23
23
|
<br />
|
|
24
24
|
|
|
25
25
|
<img src="https://dbstudio.sh/og-image.png" alt="DB Studio screenshot" width="1000" />
|
|
26
|
+
|
|
27
|
+
## Getting Started
|
|
28
|
+
|
|
29
|
+
Run DB Studio without installing it globally:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npx db-studio
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
DB Studio reads your database connection from `DATABASE_URL` in a `.env` file.
|
|
36
|
+
|
|
37
|
+
```env
|
|
38
|
+
DATABASE_URL="postgresql://user:password@127.0.0.1:5432/mydb"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
You can also pass the connection string directly:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npx db-studio --database-url "postgresql://user:password@127.0.0.1:5432/mydb"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
Add a simple script to your `package.json`:
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"scripts": {
|
|
54
|
+
"db:studio": "npx db-studio"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Then run:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm run db:studio
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Helpful options:
|
|
66
|
+
|
|
67
|
+
- `npx db-studio --env .env.local`
|
|
68
|
+
- `npx db-studio --port 4000`
|
|
69
|
+
- `npx db-studio --status`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e,L as Ie,M as Ae,N as Me,Q as Oe,U as Qe,W as qe,X as $e}from"./radix-ui-c-7GrHMM.js";import{h as ae,L as be,i as H,j as je,b as ne,a as Pe,O as Be}from"./tanstack-BaWakKkc.js";import{c as C,T as He,B as j,u as G,I as A,t as w,S as ge,a as ve,b as ye,d as Ce,e as K,C as k,f as W,g as re,D as Ve,h as Ue,i as Ke,j as Ge,k as E,l as xe,m as We,n as Xe,o as Ye,p as Je,q as Ze,r as es,s as ss,v as ts,w as as,x as ns,y as rs}from"./index-DO_12lzR.js";import{P as ls,B as os,G as is,r as l,f as me,l as le,m as oe,n as ie,o as cs,p as ds,F as us,q as Ne,S as we,E as xs,s as ms,t as hs,D as fs,u as ps,v as bs,e as js,w as gs,x as vs}from"./icons-B2mES2Qq.js";import{T as ee,a as se,b as te}from"./tooltip-B4cd0H8Q.js";import{u as X}from"./index-CESnXcY7.js";import{K as M,A as ys,a as Cs,b as Ns,c as ws,d as Ss,e as Ds,f as Ts,g as zs,h as ks,S as Fs}from"./scroll-area-D613A-kL.js";import{D as O,a as Q,b as q,c as $,d as P,e as B}from"./dialog-BtqI2R7E.js";import{u as Y}from"./queries.store-DCqn9r_M.js";import"./react-dom-BcUZDRtY.js";import"./monaco-editor-BMj4E99D.js";const he={SITE_GITHUB_LINK:"https://github.com/husamql3/db-studio",SITE_GITHUB_NEW_ISSUE_LINK:"https://github.com/husamql3/db-studio/issues/new/choose"};function Es({className:s,orientation:t="horizontal",decorative:n=!0,...r}){return e.jsx(Ie,{"data-slot":"separator",decorative:n,orientation:t,className:C("bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:w-px data-[orientation=vertical]:self-stretch",s),...r})}const Rs=()=>{const{pathname:s}=ae(),t=s.split("/")[1]||"table";return e.jsx("div",{className:"flex h-full items-center",children:He.map(n=>e.jsx(be,{to:`/${n}`,className:"h-full flex items-center",children:e.jsx(j,{variant:"ghost",className:C("flex-1 px-4 border-l-0 border-y-0 border-r border-zinc-800 h-full rounded-none",t===n?"bg-zinc-900 text-white":"text-zinc-400"),children:n})},n))})},_s=()=>{const{sidebar:{isOpen:s,isPinned:t},setSidebarOpen:n,setSidebarPinned:r}=G(),a=()=>{n(!s),r(!t)};return e.jsx(j,{variant:"ghost",onClick:a,className:"h-full aspect-square border-l-0 border-y-0 border-r border-zinc-800 rounded-none",children:e.jsx(ls,{className:"size-5"})})},Ls=()=>e.jsxs("div",{className:"border-b border-zinc-800 w-full flex items-center justify-between bg-black h-12",children:[e.jsxs("div",{className:"flex items-center h-full",children:[e.jsx(_s,{}),e.jsx(Rs,{})]}),e.jsxs("div",{className:"flex items-center h-full",children:[e.jsxs(ee,{children:[e.jsx(se,{asChild:!0,children:e.jsx(j,{variant:"ghost",className:"border-r-0 border-y-0 border-l border-zinc-800 rounded-none h-full w-12",asChild:!0,children:e.jsx("a",{href:he.SITE_GITHUB_NEW_ISSUE_LINK,target:"_blank",rel:"noopener noreferrer","aria-label":"Create a new GitHub issue",children:e.jsx(os,{className:"size-5"})})})}),e.jsx(te,{children:e.jsx("p",{children:"Report a bug"})})]}),e.jsxs(ee,{children:[e.jsx(se,{asChild:!0,children:e.jsx(j,{variant:"ghost",className:"border-r-0 border-y-0 border-l border-zinc-800 rounded-none h-full w-12",asChild:!0,children:e.jsx("a",{href:he.SITE_GITHUB_LINK,target:"_blank",rel:"noopener noreferrer","aria-label":"View the db-studio GitHub repository",children:e.jsx(is,{className:"size-5"})})})}),e.jsx(te,{children:e.jsx("p",{children:"View on GitHub"})})]})]})]});function Se({...s}){return e.jsx(Ae,{"data-slot":"context-menu",...s})}function De({className:s,...t}){return e.jsx(Me,{"data-slot":"context-menu-trigger",className:C("select-none",s),...t})}function Te({className:s,...t}){return e.jsx(Oe,{children:e.jsx(Qe,{"data-slot":"context-menu-content",className:C("data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 bg-popover text-popover-foreground min-w-32 rounded-lg p-1 shadow-md ring-1 duration-100 z-50 max-h-(--radix-context-menu-content-available-height) origin-(--radix-context-menu-content-transform-origin) overflow-x-hidden overflow-y-auto",s),...t})})}function z({className:s,inset:t,variant:n="default",...r}){return e.jsx(qe,{"data-slot":"context-menu-item","data-inset":t,"data-variant":n,className:C("focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:text-destructive not-data-[variant=destructive]:focus:**:text-accent-foreground min-h-7 gap-2 rounded-md px-2 py-1 text-xs/relaxed [&_svg:not([class*='size-'])]:size-3.5 group/context-menu-item relative flex cursor-default items-center outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0",s),...r})}function fe({className:s,...t}){return e.jsx($e,{"data-slot":"context-menu-separator",className:C("bg-border/50 -mx-1 my-1 h-px",s),...t})}const Z=({folderId:s,isExpanded:t,onToggle:n,count:r,name:a,showContextMenu:o=!1})=>{const c=H(),{deleteFolder:d,getQueriesByFolder:h,addQuery:u,updateFolder:g}=Y(),[y,m]=l.useState(!1),[b,i]=l.useState(""),[p,N]=l.useState(!1),S=l.useCallback(()=>{if(s){if(h(s).length>0){N(!0);return}d(s)}},[d,s,h]),x=l.useCallback(()=>{s&&(d(s),N(!1))},[d,s]),v=l.useCallback(()=>{const D=u(void 0,s);c({to:"/runner/$queryId",params:{queryId:D}})},[u,s,c]),T=l.useCallback(()=>{i(a),m(!0)},[a]),V=l.useCallback(()=>{s&&b.trim()&&(g(s,{name:b.trim()}),m(!1),i(""))},[s,b,g]);return e.jsxs(e.Fragment,{children:[o?e.jsxs(Se,{children:[e.jsx(De,{asChild:!0,children:e.jsxs("button",{type:"button",onClick:n,className:C("w-full flex gap-2 px-4 py-2 text-sm transition-colors text-left","hover:bg-zinc-800/50 hover:text-zinc-100 focus:outline-none focus:bg-zinc-800/50","text-zinc-400 items-center"),children:[e.jsx(me,{className:C("size-4 transition-transform duration-200",t?"rotate-90":"")}),e.jsx("span",{className:"flex-1",children:a}),e.jsx(M,{children:r})]})}),e.jsxs(Te,{children:[e.jsxs(z,{onClick:v,children:[e.jsx(le,{className:"size-4"}),"Add a new query"]}),e.jsxs(z,{onClick:T,children:[e.jsx(oe,{className:"size-4"}),"Rename folder"]}),e.jsxs(z,{onClick:S,children:[e.jsx(ie,{className:"size-4"}),"Delete folder"]})]})]}):e.jsxs("button",{type:"button",onClick:n,className:C("w-full flex gap-2 px-4 py-2 text-sm transition-colors text-left","hover:bg-zinc-800/50 hover:text-zinc-100 focus:outline-none focus:bg-zinc-800/50","text-zinc-400 items-center"),children:[e.jsx(me,{className:C("size-4 transition-transform duration-200",t?"rotate-90":"")}),e.jsx("span",{className:"flex-1",children:a}),e.jsx(M,{children:r})]}),e.jsx(O,{open:y,onOpenChange:m,children:e.jsxs(Q,{children:[e.jsxs(q,{children:[e.jsx($,{children:"Rename Folder"}),e.jsx(P,{children:"Enter a new name for this folder."})]}),e.jsx(A,{value:b,onChange:D=>i(D.target.value),placeholder:"Folder name",onKeyDown:D=>{D.key==="Enter"&&V()},autoFocus:!0}),e.jsxs(B,{children:[e.jsx(j,{variant:"outline",onClick:()=>{m(!1),i("")},children:"Cancel"}),e.jsx(j,{onClick:V,disabled:!b.trim(),children:"Rename"})]})]})}),e.jsx(ys,{open:p,onOpenChange:N,children:e.jsxs(Cs,{children:[e.jsxs(Ns,{children:[e.jsx(ws,{children:"Delete Folder"}),e.jsxs(Ss,{children:["This folder contains ",r," ",r===1?"query":"queries",". Deleting this folder will also delete all queries inside it. This action cannot be undone."]})]}),e.jsxs(Ds,{children:[e.jsx(Ts,{children:"Cancel"}),e.jsx(zs,{onClick:x,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete Folder"})]})]})})]})},U=({id:s,tableName:t,isNested:n=!1,showContextMenu:r=!0})=>{const a=H(),{deleteQuery:o,addQuery:c,getQuery:d,toggleFavorite:h,updateQuery:u,moveQuery:g,folders:y,addFolder:m}=Y(),{queryId:b}=je({strict:!1}),i=b===s,p=d(s),N=p?.isFavorite??!1,[S,x]=l.useState(!1),[v,T]=l.useState(""),[V,D]=l.useState(!1),[J,R]=l.useState(void 0),[_,F]=l.useState(!1),[L,I]=l.useState(""),ce=l.useCallback(()=>{a({to:"/runner/$queryId",params:{queryId:s}})},[a,s]),ze=l.useCallback(()=>{o(s),b===s&&a({to:"/runner"}),w.success("Query deleted successfully")},[o,s,a,b]),ke=l.useCallback(()=>{const f=d(s),Le=c(`${f?.name} (Copy)`);a({to:"/runner/$queryId",params:{queryId:Le}}),w.success("Query duplicated successfully")},[c,d,a,s]),Fe=l.useCallback(()=>{h(s),w.success("Query favorited successfully")},[h,s]),Ee=l.useCallback(()=>{T(p?.name??""),x(!0)},[p?.name]),de=l.useCallback(()=>{v.trim()&&(u(s,{name:v.trim()}),x(!1),T(""),w.success("Query renamed successfully"))},[s,v,u]),Re=l.useCallback(()=>{R(p?.folderId),F(!1),I(""),D(!0)},[p?.folderId]),_e=l.useCallback(f=>{f==="__create_new__"?(F(!0),R(void 0)):(F(!1),R(f==="__none__"?void 0:f))},[]),ue=l.useCallback(()=>{if(_&&L.trim()){const f=Math.random().toString(36).substring(2,15);m({id:f,name:L.trim(),isExpanded:!0,isFavorite:!1}),g(s,f),w.success("Query moved to new folder successfully")}else _||(g(s,J),w.success("Query moved to selected folder successfully"));D(!1),F(!1),I(""),R(void 0)},[_,L,J,s,m,g]);return e.jsxs("li",{className:"relative",children:[r?e.jsxs(Se,{children:[e.jsx(De,{asChild:!0,children:e.jsxs("button",{type:"button",onClick:ce,className:C("w-full flex gap-2 py-2 text-sm transition-colors text-left","hover:text-zinc-100 focus:outline-none focus:bg-accent/10 focus:text-zinc-100 justify-start items-center",i?"text-zinc-100 bg-accent/10":"text-zinc-400",n?"px-4 pl-12":"px-4"),children:[i&&e.jsx("span",{className:"absolute left-0 top-0 bottom-0 w-1 bg-accent"}),e.jsx("span",{className:"flex-1",children:t})]})}),e.jsxs(Te,{children:[e.jsxs(z,{onClick:Ee,children:[e.jsx(oe,{className:"size-4"}),"Rename query"]}),e.jsxs(z,{onClick:ke,children:[e.jsx(cs,{className:"size-4"}),"Duplicate query"]}),e.jsxs(z,{onClick:Fe,children:[e.jsx(ds,{className:N?"size-4 fill-current":"size-4"}),N?"Remove from favorites":"Add to favorites"]}),e.jsx(fe,{}),e.jsxs(z,{onClick:Re,children:[e.jsx(us,{className:"size-4"}),"Move to folder"]}),e.jsx(fe,{}),e.jsxs(z,{onClick:ze,children:[e.jsx(ie,{className:"size-4"}),"Delete query"]})]})]}):e.jsxs("button",{type:"button",onClick:ce,className:C("w-full flex gap-2 py-2 text-sm transition-colors text-left","hover:text-zinc-100 focus:outline-none focus:bg-accent/10 focus:text-zinc-100 justify-start items-center",i?"text-zinc-100 bg-accent/10":"text-zinc-400",n?"px-4 pl-12":"px-4"),children:[i&&e.jsx("span",{className:"absolute left-0 top-0 bottom-0 w-1 bg-accent"}),e.jsx("span",{className:"flex-1",children:t})]}),e.jsx(O,{open:S,onOpenChange:x,children:e.jsxs(Q,{children:[e.jsxs(q,{children:[e.jsx($,{children:"Rename Query"}),e.jsx(P,{children:"Enter a new name for this query."})]}),e.jsx(A,{value:v,onChange:f=>T(f.target.value),placeholder:"Query name",onKeyDown:f=>{f.key==="Enter"&&de()},autoFocus:!0}),e.jsxs(B,{children:[e.jsx(j,{variant:"outline",onClick:()=>{x(!1),T("")},children:"Cancel"}),e.jsx(j,{onClick:de,disabled:!v.trim(),children:"Rename"})]})]})}),e.jsx(O,{open:V,onOpenChange:f=>{D(f),f||(F(!1),I(""),R(void 0))},children:e.jsxs(Q,{children:[e.jsxs(q,{children:[e.jsx($,{children:"Move to Folder"}),e.jsx(P,{children:"Select a folder to move this query to."})]}),e.jsx("div",{className:"space-y-4",children:_?e.jsx(A,{value:L,onChange:f=>I(f.target.value),placeholder:"Folder name",onKeyDown:f=>{f.key==="Enter"&&L.trim()&&ue(),f.key==="Escape"&&(F(!1),I(""))},autoFocus:!0}):e.jsxs(ge,{value:J??"__none__",onValueChange:_e,children:[e.jsx(ve,{className:"w-full",children:e.jsx(ye,{placeholder:"Select a folder"})}),e.jsxs(Ce,{children:[e.jsx(K,{value:"__none__",children:"No folder"}),y.map(f=>e.jsx(K,{value:f.id,children:f.name},f.id)),e.jsx(K,{value:"__create_new__",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ne,{className:"size-4"}),"Create a new folder"]})})]})]})}),e.jsxs(B,{children:[e.jsx(j,{variant:"outline",onClick:()=>{D(!1),F(!1),I(""),R(void 0)},children:"Cancel"}),e.jsx(j,{onClick:ue,disabled:_&&!L.trim(),children:_?"Create & Move":"Move"})]})]})})]})},Is=()=>{const[s]=X(k.SIDEBAR_SEARCH,{defaultValue:""}),{folders:t,queries:n,getFavoriteQueries:r,getQueriesByFolder:a,toggleFolder:o}=Y(),[c,d]=l.useState(!0),[h,u]=l.useState(!0),g=n.filter(i=>!i.isFavorite).length,y=r(),m=y.length,b=n.filter(i=>!i.folderId&&!i.isFavorite);if(s){const i=n.filter(p=>p.name.toLowerCase().includes(s.toLowerCase()));return i.length===0?e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:"No queries found matching"}):e.jsx("div",{className:"flex-1 overflow-y-auto",children:i.map(p=>e.jsx(U,{id:p.id,tableName:p.name},p.id))})}return e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[e.jsx(Z,{name:"Favorites",isExpanded:c,onToggle:()=>d(!c),count:m}),c&&y.map(i=>e.jsx(U,{id:i.id,tableName:i.name},i.id)),e.jsx(Es,{className:"bg-zinc-800"}),e.jsx(Z,{name:"Queries",isExpanded:h,onToggle:()=>u(!h),count:g}),h&&e.jsxs(e.Fragment,{children:[t.map(i=>{const p=a(i.id),N=p.length;return e.jsxs("div",{children:[e.jsx(Z,{folderId:i.id,name:i.name,isExpanded:i.isExpanded,onToggle:()=>o(i.id),count:N,showContextMenu:!0}),i.isExpanded&&p.map(S=>e.jsx(U,{id:S.id,tableName:S.name,isNested:!0,showContextMenu:!0},S.id))]},i.id)}),b.map(i=>e.jsx(U,{id:i.id,tableName:i.name,showContextMenu:!0},i.id))]})]})},As=()=>{const{addQuery:s,addFolder:t}=Y(),n=H(),r=l.useRef(null),[a,o]=X(k.SIDEBAR_SEARCH,{defaultValue:""}),c=u=>{o(u.target.value)},d=()=>{const u=s();n({to:"/runner/$queryId",params:{queryId:u}})},h=()=>{const u=Math.random().toString(36).substring(2,15);t({id:u,name:"New Folder",isExpanded:!0,isFavorite:!1})};return e.jsxs("div",{className:"p-3 space-y-2 border-b border-zinc-800",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(j,{className:"flex-1 justify-start h-8",onClick:d,children:[e.jsx(le,{className:"size-4"}),"Add Query"]}),e.jsxs(j,{className:"flex-1 justify-start h-8",onClick:h,children:[e.jsx(Ne,{className:"size-4"}),"Add Folder"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(we,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(A,{ref:r,placeholder:"Search queries",value:a??"",onChange:c,className:"rounded-sm h-8 pl-8 pr-8"}),e.jsx(M,{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs",children:"/"})]})]})},Ms=()=>e.jsxs(e.Fragment,{children:[e.jsx(As,{}),e.jsx(Is,{})]}),Os=()=>{const{selectedDatabase:s}=W(),{mutateAsync:t,isPending:n}=ne({mutationFn:async a=>{const c=(await re.get(`/tables/${a}/schema`,{params:{db:s??""}})).data.data.schema;return await navigator.clipboard.writeText(c),c}});return{copyTableSchema:async a=>w.promise(t(a),{loading:"Copying table schema...",success:"Table schema copied to clipboard",error:o=>o.message||"Failed to copy table schema"}),isCopyingSchema:n}},Qs=()=>{const s=Pe(),{selectedDatabase:t}=W(),{mutateAsync:n,isPending:r,reset:a}=ne({mutationFn:async({tableName:d,cascade:h=!1})=>(await re.delete(`/tables/${d}`,{params:{db:t??"",cascade:h?"true":"false"}})).data.data,onSuccess:async()=>{await s.invalidateQueries({queryKey:[k.CACHE_KEYS.TABLES_LIST]})}});return{deleteTable:async d=>n({tableName:d,cascade:!1}),forceDeleteTable:async d=>n({tableName:d,cascade:!0}),isDeletingTable:r,resetDeleteResult:a}},qs=()=>{const{selectedDatabase:s}=W(),{mutateAsync:t,isPending:n}=ne({mutationFn:async({tableName:a,format:o})=>{const c=await re.get(`/tables/${a}/export`,{params:{db:s??"",format:o},responseType:"blob"}),u=c.headers["content-disposition"]?.match(/filename="(.+)"/)?.[1]||`${a}_export.${o}`,g=new Blob([c.data],{type:c.headers["content-type"]}),y=window.URL.createObjectURL(g),m=document.createElement("a");m.href=y,m.download=u,document.body.appendChild(m),m.click(),document.body.removeChild(m),window.URL.revokeObjectURL(y)}});return{exportFile:async({tableName:a,format:o})=>w.promise(t({tableName:a,format:o}),{loading:"Exporting file...",success:"File exported successfully",error:c=>c.message||"Failed to export file"}),isExportingFile:n}},$s=({tableName:s})=>{const t=H(),{copyTableSchema:n,isCopyingSchema:r}=Os(),{exportFile:a,isExportingFile:o}=qs(),{deleteTable:c,forceDeleteTable:d,isDeletingTable:h}=Qs(),[u,g]=l.useState(!1),[y,m]=l.useState(!1),[b,i]=l.useState([]),p=()=>{navigator.clipboard.writeText(s),w.success("Table name copied to clipboard")},N=async()=>{const v=await c(s);v.fkViolation?(i(v.relatedRecords),g(!1),m(!0)):(w.success(`Deleted table "${s}" with ${v.deletedCount} rows`),g(!1),t({to:"/"}))},S=async()=>{const v=await d(s);w.success(`Force deleted table "${s}" with ${v.deletedCount} rows`),m(!1),t({to:"/"})},x=()=>{m(!1),i([])};return e.jsxs(e.Fragment,{children:[e.jsxs(Ve,{children:[e.jsx(Ue,{children:e.jsx(j,{variant:"ghost",size:"icon-sm",children:e.jsx(xs,{})})}),e.jsx(Ke,{className:"w-56",align:"start",children:e.jsxs(Ge,{children:[e.jsxs(E,{onClick:p,children:[e.jsx(ms,{className:"size-4"}),"Copy name"]}),e.jsxs(E,{onClick:()=>n(s),disabled:r,children:[e.jsx(hs,{className:"size-4"}),"Copy table schema"]}),e.jsx(xe,{}),e.jsxs(E,{onClick:()=>t({to:"/schema/$table",params:{table:s}}),children:[e.jsx(oe,{className:"size-4"}),"Edit table"]}),e.jsxs(We,{children:[e.jsxs(Xe,{children:[e.jsx(fs,{className:"size-4"}),"Export data"]}),e.jsxs(Ye,{children:[e.jsx(E,{onClick:()=>a({tableName:s,format:"csv"}),disabled:o,children:"Export as CSV"}),e.jsx(E,{onClick:()=>a({tableName:s,format:"json"}),disabled:o,children:"Export as JSON"}),e.jsx(E,{onClick:()=>a({tableName:s,format:"xlsx"}),disabled:o,children:"Export as Excel"})]})]}),e.jsx(xe,{}),e.jsxs(E,{variant:"destructive",onClick:()=>g(!0),children:[e.jsx(ie,{className:"size-4"}),"Delete table"]})]})})]}),e.jsx(Ps,{isOpen:u,onOpenChange:g,tableName:s,onDelete:N,isDeleting:h}),e.jsx(Bs,{isOpen:y,onOpenChange:m,tableName:s,relatedRecords:b,onForceDelete:S,onCancel:x,isDeleting:h})]})},Ps=({isOpen:s,onOpenChange:t,tableName:n,onDelete:r,isDeleting:a})=>e.jsx(O,{open:s,onOpenChange:t,children:e.jsxs(Q,{className:"max-w-md",children:[e.jsxs(q,{children:[e.jsx($,{children:"Delete Table"}),e.jsxs(P,{children:["Are you sure you want to delete the table"," ",e.jsxs("span",{className:"font-semibold text-foreground",children:['"',n,'"']}),"? This action cannot be undone and all data will be permanently lost."]})]}),e.jsxs(B,{className:"gap-2",children:[e.jsx(j,{variant:"outline",onClick:()=>t(!1),disabled:a,children:"Cancel"}),e.jsx(j,{variant:"destructive",onClick:r,disabled:a,children:a?"Deleting...":"Delete Table"})]})]})}),Bs=({isOpen:s,onOpenChange:t,tableName:n,relatedRecords:r,onForceDelete:a,onCancel:o,isDeleting:c})=>e.jsx(O,{open:s,onOpenChange:t,children:e.jsxs(Q,{className:"max-w-xl! max-h-[calc(100vh-1rem)]!",children:[e.jsxs(q,{children:[e.jsx($,{children:"Cannot Delete - Foreign Key Constraint"}),e.jsxs(P,{children:["The table ",e.jsxs("span",{className:"font-semibold text-foreground",children:['"',n,'"']})," ","cannot be deleted because it is referenced by records in other tables. You can either cancel the operation or force delete, which will also delete all related records."]})]}),e.jsx("div",{className:"space-y-4 max-h-64 overflow-y-auto",children:r.map((d,h)=>e.jsxs("div",{className:"border border-zinc-700 rounded-md p-3",children:[e.jsxs("div",{className:"font-medium text-sm mb-2",children:["Table: ",e.jsx("span",{className:"text-primary",children:d.tableName}),e.jsxs("span",{className:"text-muted-foreground ml-2",children:["(",d.records.length," record",d.records.length!==1?"s":"",")"]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground mb-2",children:["References column: ",d.columnName]}),e.jsx("div",{className:"bg-zinc-900 rounded p-2 text-xs overflow-x-auto",children:e.jsxs("pre",{className:"whitespace-pre-wrap",children:[JSON.stringify(d.records.slice(0,5),null,2),d.records.length>5&&e.jsxs("div",{className:"text-muted-foreground mt-2",children:["... and ",d.records.length-5," more"]})]})})]},`${d.tableName}-${d.columnName}-${h}`))}),e.jsxs(B,{className:"gap-2",children:[e.jsx(j,{variant:"outline",onClick:o,disabled:c,children:"Cancel"}),e.jsx(j,{variant:"destructive",onClick:a,disabled:c,children:c?"Deleting...":"Force Delete All"})]})]})}),Hs=({tableName:s,rowCount:t})=>{const n=je({strict:!1}),{pathname:r}=ae(),o=n.table===s,c=r.startsWith("/schema")?"/schema/$table":"/table/$table";return e.jsx("li",{className:"relative",children:e.jsxs(be,{to:c,params:{table:s},className:C("w-full flex gap-0.5 px-4 py-1.5 text-sm transition-colors text-left","hover:text-zinc-100 focus:outline-none focus:bg-accent/10 focus:text-zinc-100 justify-start items-center",o?"text-white bg-zinc-800/50":"text-zinc-400"),children:[o&&e.jsx("span",{className:"absolute left-0 top-0 bottom-0 w-1 bg-accent"}),e.jsx("span",{className:"flex-1",children:s}),e.jsxs("div",{className:"flex items-center gap-1 h-5",children:[o&&e.jsx($s,{tableName:s}),e.jsx(M,{children:t})]})]})})},Vs=()=>{const[s]=X(k.SIDEBAR_SEARCH,{defaultValue:""}),{tablesList:t=[],isLoadingTablesList:n,errorTablesList:r}=Je(),a=t?.filter(o=>o.tableName.toLowerCase().includes(s.toLowerCase()));return n?e.jsx("div",{className:"flex-1 h-full overflow-y-auto pb-3 flex items-center justify-center",children:e.jsx(Ze,{size:"size-6"})}):r?e.jsxs("div",{className:"flex-1 overflow-y-auto pb-3 h-full flex items-center justify-center",children:["Error: ",r.message]}):e.jsx("div",{className:"flex-1 overflow-y-auto pb-3",children:a&&a.length>0?e.jsx("ul",{children:a?.map(o=>e.jsx(Hs,{tableName:o.tableName,rowCount:o.rowCount},o.tableName))}):s?e.jsx("div",{className:"flex-1 overflow-y-auto pb-3 h-full flex items-center justify-center",children:"No tables found matching"}):e.jsx("div",{className:"flex-1 overflow-y-auto pb-3 h-full flex items-center justify-center",children:"No tables available"})})},Us=()=>{const s=l.useRef(null),[t,n]=X(k.SIDEBAR_SEARCH,{defaultValue:""}),{openSheet:r}=es();return ks("/",a=>{a.preventDefault(),s.current&&s.current.focus()},{preventDefault:!0}),e.jsxs("div",{className:"p-3 space-y-2",children:[e.jsxs(j,{className:"w-full justify-start h-8",onClick:()=>r("add-table"),children:[e.jsx(le,{className:"size-4"}),"Add Table"]}),e.jsxs("div",{className:"relative",children:[e.jsx(we,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(A,{ref:s,placeholder:"Search tables",value:t??"",onChange:a=>n(a.target.value.trim()),className:"rounded-sm h-8 pl-8 pr-8"}),e.jsx(M,{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs",children:"/"})]})]})},pe=()=>e.jsxs(e.Fragment,{children:[e.jsx(Us,{}),e.jsx(Fs,{className:"flex-1 overflow-y-auto pb-3 block h-full w-full",children:e.jsx(Vs,{})})]});function Ks(){const{databases:s,isLoadingDatabases:t,refetchDatabases:n,isRefetchingDatabases:r}=ss(),{connectionInfo:a,isLoadingConnectionInfo:o}=ts(),{selectedDatabase:c,setSelectedDatabase:d}=W(),h=H(),[u,g]=l.useState(!1),y=b=>{d(b),h({to:"/table",search:{}})},m=async()=>{await n(),w.success("Databases refreshed")};return e.jsx("div",{className:"mt-auto border-t bg-background",children:e.jsxs("div",{className:"p-4 space-y-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ps,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium",children:"Database"})]}),e.jsxs(ee,{children:[e.jsx(se,{asChild:!0,children:e.jsx(j,{variant:"ghost",size:"icon",className:"h-6 w-6 hover:bg-accent",onClick:m,disabled:t||r,children:e.jsx(bs,{className:C("h-3.5 w-3.5",(t||r)&&"animate-spin")})})}),e.jsx(te,{children:"Refresh databases"})]})]}),e.jsxs(ge,{value:c||"",onValueChange:y,children:[e.jsx(ve,{className:"h-9 text-xs font-mono w-full",disabled:t||r,children:e.jsx(ye,{placeholder:"Select database..."})}),e.jsx(Ce,{children:s?.map(b=>e.jsx(K,{value:b.name,className:"font-mono text-xs",children:b.name},b.name))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(j,{variant:"ghost",className:"w-full hover:bg-accent flex items-center justify-between",onClick:()=>g(!u),disabled:o||r,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex items-center justify-center",children:e.jsxs("div",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-green-500"})]})}),e.jsx("span",{className:"text-xs font-medium text-green-600",children:"Connected"})]}),e.jsx(js,{className:C("size-3 text-muted-foreground transition-transform",u&&"rotate-180")})]}),u&&a&&e.jsxs("div",{className:"space-y-1.5 px-2 py-2 rounded-md bg-muted/30",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Host"}),e.jsxs("span",{className:"text-xs font-mono text-foreground",children:[a.host,":",a.port]})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"User"}),e.jsx("span",{className:"text-xs font-mono text-foreground",children:a.user})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Databases"}),e.jsx("span",{className:"text-xs font-mono font-medium text-foreground",children:s?.length||0})]})]})]})]})})}const Gs=()=>{const{sidebar:{isPinned:s},toggleSidebarPinned:t}=G();return e.jsx("div",{className:"flex items-center justify-between h-9 border-b border-zinc-800",children:e.jsx(j,{variant:"ghost",size:"lg",onClick:t,className:"size-9 flex items-center justify-center transition hover:bg-transparent! focus-visible:ring-0 focus-visible:ring-offset-0",title:s?"Unpin sidebar":"Pin sidebar",children:s?e.jsx(gs,{className:"size-4"}):e.jsx(vs,{className:"size-4"})})})},Ws=({children:s})=>{const{sidebar:{width:t,isOpen:n,isPinned:r},setSidebarWidth:a,setSidebarOpen:o}=G(),c=l.useRef(!1),d=l.useRef(0),h=l.useRef(0),u=l.useRef(null),g=l.useRef(null),y=l.useCallback(x=>{c.current&&requestAnimationFrame(()=>{const v=x.clientX-d.current,T=h.current+v;a(T)})},[a]),m=l.useCallback(()=>{c.current=!1,document.body.style.cursor="",document.body.style.userSelect="";const x=document.getElementById("resize-overlay");x&&x.remove()},[]),b=l.useCallback(x=>{x.preventDefault(),c.current=!0,d.current=x.clientX,h.current=t,document.body.style.cursor="col-resize",document.body.style.userSelect="none";const v=document.createElement("div");v.id="resize-overlay",v.style.cssText="position:fixed;inset:0;z-index:9999;cursor:col-resize;",document.body.appendChild(v)},[t]),i=l.useCallback(()=>{r||o(!0)},[r,o]),p=l.useCallback(()=>{r||o(!1)},[r,o]),N=l.useCallback(x=>{r||n||c.current||(x.clientX<=k.HOVER_ZONE?(u.current&&clearTimeout(u.current),u.current=window.setTimeout(()=>{o(!0)},k.HOVER_DELAY)):x.clientX>k.HOVER_ZONE+50&&u.current&&clearTimeout(u.current))},[r,n,o]),S=x=>{r||o(x)};return l.useEffect(()=>(document.addEventListener("mousemove",y),document.addEventListener("mouseup",m),document.addEventListener("mousemove",N),()=>{document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",m),document.removeEventListener("mousemove",N),u.current&&clearTimeout(u.current)}),[y,m,N]),l.useEffect(()=>{const x=g.current;if(x)return x.addEventListener("mouseenter",i),x.addEventListener("mouseleave",p),()=>{x.removeEventListener("mouseenter",i),x.removeEventListener("mouseleave",p)}},[i,p]),e.jsxs(as,{open:n,onOpenChange:S,modal:!1,children:[e.jsx(ns,{className:"sr-only",children:"Open Sidebar"}),e.jsx(rs,{ref:g,side:"left",showCloseButton:!1,isPinned:r,className:C("bg-black border-r border-zinc-800 p-0","transition-transform duration-300 ease-out"),style:{width:`${t}px`},onOpenAutoFocus:x=>x.preventDefault(),children:e.jsxs("div",{className:"relative h-full flex flex-col",children:[s,e.jsx("div",{role:"button",tabIndex:0,onMouseDown:b,className:C("absolute top-0 right-0 w-2 h-full cursor-col-resize z-50","hover:bg-blue-500/50 transition-colors group"),title:"Drag to resize",children:e.jsx("div",{className:"absolute right-0 top-1/2 -translate-y-1/2 w-2 h-12 bg-blue-500 opacity-0 group-hover:opacity-100 transition-opacity rounded-full"})})]})})]})},Xs=()=>{const{pathname:s}=ae(),t=s.split("/")[1],n=l.useMemo(()=>{switch(console.log(t),t){case"":case"table":case"schema":return e.jsx(pe,{});case"runner":return e.jsx(Ms,{});default:return e.jsx(pe,{})}},[t]);return e.jsxs(Ws,{children:[e.jsx(Gs,{}),n,e.jsx(Ks,{})]})};function it(){const{sidebar:{isPinned:s,width:t}}=G();return e.jsxs("div",{className:"bg-zinc-950 w-dvw flex h-dvh max-h-dvh overflow-hidden relative",children:[e.jsx(Xs,{}),e.jsxs("div",{className:"flex-1 flex flex-col h-full overflow-hidden ",style:{marginLeft:s?`${t}px`:"0"},children:[e.jsx(Ls,{}),e.jsx(Be,{})]})]})}export{it as component};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as r}from"./radix-ui-c-7GrHMM.js";import{R as t}from"./runner-tab-CloOoJUy.js";import{aa as m}from"./index-DO_12lzR.js";import"./icons-B2mES2Qq.js";import"./react-dom-BcUZDRtY.js";import"./monaco-editor-BMj4E99D.js";import"./tanstack-BaWakKkc.js";import"./index-CESnXcY7.js";import"./format-cell-value-Cn3RA9a1.js";import"./tooltip-B4cd0H8Q.js";import"./queries.store-DCqn9r_M.js";function j(){const{queryId:o}=m.useParams();return r.jsx(t,{queryId:o})}export{j as component};
|