Re-use big union statement for get_center_pane
This commit is contained in:
parent
f27a9d77d1
commit
64ac84fdf4
1 changed files with 26 additions and 18 deletions
|
@ -1,6 +1,6 @@
|
||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use indoc::indoc;
|
use indoc::indoc;
|
||||||
use sqlez::migrations::Migration;
|
use sqlez::{migrations::Migration, statement::Statement};
|
||||||
use util::unzip_option;
|
use util::unzip_option;
|
||||||
|
|
||||||
use crate::model::{Axis, GroupId, PaneId, SerializedPane};
|
use crate::model::{Axis, GroupId, PaneId, SerializedPane};
|
||||||
|
@ -39,19 +39,7 @@ impl Db {
|
||||||
&self,
|
&self,
|
||||||
workspace_id: &WorkspaceId,
|
workspace_id: &WorkspaceId,
|
||||||
) -> Result<SerializedPaneGroup> {
|
) -> Result<SerializedPaneGroup> {
|
||||||
self.get_pane_group_children(workspace_id, None)?
|
let mut query = self.prepare(indoc! {"
|
||||||
.into_iter()
|
|
||||||
.next()
|
|
||||||
.context("No center pane group")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_pane_group_children(
|
|
||||||
&self,
|
|
||||||
workspace_id: &WorkspaceId,
|
|
||||||
group_id: Option<GroupId>,
|
|
||||||
) -> Result<Vec<SerializedPaneGroup>> {
|
|
||||||
let children = self
|
|
||||||
.prepare(indoc! {"
|
|
||||||
SELECT group_id, axis, pane_id
|
SELECT group_id, axis, pane_id
|
||||||
FROM (SELECT group_id, axis, NULL as pane_id, position, parent_group_id, workspace_id
|
FROM (SELECT group_id, axis, NULL as pane_id, position, parent_group_id, workspace_id
|
||||||
FROM pane_groups
|
FROM pane_groups
|
||||||
|
@ -62,9 +50,25 @@ impl Db {
|
||||||
WHERE parent_group_id IS NOT NULL and position IS NOT NULL)
|
WHERE parent_group_id IS NOT NULL and position IS NOT NULL)
|
||||||
WHERE parent_group_id IS ? AND workspace_id = ?
|
WHERE parent_group_id IS ? AND workspace_id = ?
|
||||||
ORDER BY position
|
ORDER BY position
|
||||||
"})?
|
"})?;
|
||||||
.with_bindings((group_id, workspace_id))?
|
|
||||||
.rows::<(Option<GroupId>, Option<Axis>, Option<PaneId>)>()?;
|
self.get_pane_group_children(workspace_id, None, &mut query)?
|
||||||
|
.into_iter()
|
||||||
|
.next()
|
||||||
|
.context("No center pane group")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_pane_group_children(
|
||||||
|
&self,
|
||||||
|
workspace_id: &WorkspaceId,
|
||||||
|
group_id: Option<GroupId>,
|
||||||
|
query: &mut Statement,
|
||||||
|
) -> Result<Vec<SerializedPaneGroup>> {
|
||||||
|
let children = query.with_bindings((group_id, workspace_id))?.rows::<(
|
||||||
|
Option<GroupId>,
|
||||||
|
Option<Axis>,
|
||||||
|
Option<PaneId>,
|
||||||
|
)>()?;
|
||||||
|
|
||||||
children
|
children
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -72,7 +76,11 @@ impl Db {
|
||||||
if let Some((group_id, axis)) = group_id.zip(axis) {
|
if let Some((group_id, axis)) = group_id.zip(axis) {
|
||||||
Ok(SerializedPaneGroup::Group {
|
Ok(SerializedPaneGroup::Group {
|
||||||
axis,
|
axis,
|
||||||
children: self.get_pane_group_children(workspace_id, Some(group_id))?,
|
children: self.get_pane_group_children(
|
||||||
|
workspace_id,
|
||||||
|
Some(group_id),
|
||||||
|
query,
|
||||||
|
)?,
|
||||||
})
|
})
|
||||||
} else if let Some(pane_id) = pane_id {
|
} else if let Some(pane_id) = pane_id {
|
||||||
Ok(SerializedPaneGroup::Pane(SerializedPane {
|
Ok(SerializedPaneGroup::Pane(SerializedPane {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue