Added Query

This commit is contained in:
2021-12-16 21:56:45 -06:00
parent 424e0865c2
commit 523f59463b
2 changed files with 34 additions and 0 deletions

View File

@@ -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
View 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(())
}
}