move utils into database module

pull/35/head
Takayuki Maeda 3 years ago
parent 8f26ffed09
commit 781f07f211

@ -1,7 +1,7 @@
use crate::clipboard::Clipboard;
use crate::components::{CommandInfo, Component as _, DrawableComponent as _, EventState};
use crate::database::{MySqlPool, Pool, RECORDS_LIMIT_PER_PAGE};
use crate::event::Key;
use crate::utils::{MySqlPool, Pool};
use crate::{
components::tab::Tab,
components::{
@ -268,10 +268,7 @@ impl App {
}
if let Some(index) = self.record_table.table.selected_row.selected() {
if index.saturating_add(1)
% crate::utils::RECORDS_LIMIT_PER_PAGE as usize
== 0
{
if index.saturating_add(1) % RECORDS_LIMIT_PER_PAGE as usize == 0 {
if let Some((database, table)) =
self.databases.tree().selected_table()
{

@ -0,0 +1,27 @@
pub mod mysql;
pub use mysql::MySqlPool;
use async_trait::async_trait;
use database_tree::{Database, Table};
pub const RECORDS_LIMIT_PER_PAGE: u8 = 200;
#[async_trait]
pub trait Pool {
async fn get_databases(&self) -> anyhow::Result<Vec<Database>>;
async fn get_tables(&self, database: String) -> anyhow::Result<Vec<Table>>;
async fn get_records(
&self,
database: &str,
table: &str,
page: u16,
filter: Option<String>,
) -> anyhow::Result<(Vec<String>, Vec<Vec<String>>)>;
async fn get_columns(
&self,
database: &str,
table: &str,
) -> anyhow::Result<(Vec<String>, Vec<Vec<String>>)>;
async fn close(&self);
}

@ -1,30 +1,10 @@
use super::{Pool, RECORDS_LIMIT_PER_PAGE};
use async_trait::async_trait;
use chrono::NaiveDate;
use database_tree::{Database, Table};
use futures::TryStreamExt;
use sqlx::mysql::{MySqlColumn, MySqlPool as MPool, MySqlRow};
use sqlx::{Column as _, Row, TypeInfo};
pub const RECORDS_LIMIT_PER_PAGE: u8 = 200;
#[async_trait]
pub trait Pool {
async fn get_databases(&self) -> anyhow::Result<Vec<Database>>;
async fn get_tables(&self, database: String) -> anyhow::Result<Vec<Table>>;
async fn get_records(
&self,
database: &str,
table: &str,
page: u16,
filter: Option<String>,
) -> anyhow::Result<(Vec<String>, Vec<Vec<String>>)>;
async fn get_columns(
&self,
database: &str,
table: &str,
) -> anyhow::Result<(Vec<String>, Vec<Vec<String>>)>;
async fn close(&self);
}
use sqlx::{Column as _, Row as _, TypeInfo as _};
pub struct MySqlPool {
pool: MPool,

@ -2,9 +2,9 @@ mod app;
mod clipboard;
mod components;
mod config;
mod database;
mod event;
mod ui;
mod utils;
#[macro_use]
mod log;

Loading…
Cancel
Save