Added Query
This commit is contained in:
@@ -2,6 +2,7 @@ use std::error::Error;
|
|||||||
|
|
||||||
mod converter;
|
mod converter;
|
||||||
mod types;
|
mod types;
|
||||||
|
mod query;
|
||||||
|
|
||||||
use clap::{App, Arg, SubCommand};
|
use clap::{App, Arg, SubCommand};
|
||||||
|
|
||||||
@@ -45,6 +46,12 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
//Get Top
|
//Get Top
|
||||||
match matches.values_of("get-top") {
|
match matches.values_of("get-top") {
|
||||||
Some(vals) => {
|
Some(vals) => {
|
||||||
|
let data: Vec<&str> = vals.collect();
|
||||||
|
let year = data[0].parse::<i32>()?;
|
||||||
|
let month = data[1].parse::<i32>()?;
|
||||||
|
|
||||||
|
let q = query::Query::new()?;
|
||||||
|
q.get_top(year, month)?;
|
||||||
did_run = true;
|
did_run = true;
|
||||||
},
|
},
|
||||||
None => {}
|
None => {}
|
||||||
|
|||||||
27
src/query/mod.rs
Normal file
27
src/query/mod.rs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
use rusqlite::{Connection, Result};
|
||||||
|
use std::error::Error;
|
||||||
|
|
||||||
|
pub struct Query{
|
||||||
|
conn: Connection,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Query{
|
||||||
|
pub fn new() -> Result<Query,Box<dyn Error>> {
|
||||||
|
let conn = Connection::open("data.db")?;
|
||||||
|
Ok(Query{
|
||||||
|
conn: conn
|
||||||
|
})
|
||||||
|
}
|
||||||
|
pub fn get_top(&self, year: i32, month: i32) -> Result<(),Box<dyn Error>> {
|
||||||
|
let mut stmt = self.conn.prepare("SELECT * FROM data limit 10;")?;
|
||||||
|
let get_itr = stmt.query_map([], |row| {
|
||||||
|
let res: i32 = row.get(0)?;
|
||||||
|
Ok(res)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
for elm in get_itr {
|
||||||
|
dbg!(elm)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user