aboutsummaryrefslogtreecommitdiff
path: root/src/db.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-08-23 15:32:53 +0100
committerAkshay <[email protected]>2020-08-23 15:32:53 +0100
commite16743598ccdaae9709034a7215c35ccfe2a49fa (patch)
treef9180a143c3a4d48185c52113aa23a44b2cff7a7 /src/db.rs
parent99d59ca3be5ce319e43671f63449b36344bb3f84 (diff)
refactor src into db and service
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/db.rs b/src/db.rs
new file mode 100644
index 0000000..a5c0f85
--- /dev/null
+++ b/src/db.rs
@@ -0,0 +1,19 @@
1use anyhow::Result;
2use rusqlite::{Connection, OpenFlags, NO_PARAMS};
3
4use std::path::Path;
5
6pub fn init_db<P: AsRef<Path>>(p: P) -> Result<Connection> {
7 let conn = Connection::open_with_flags(
8 p,
9 OpenFlags::SQLITE_OPEN_CREATE | OpenFlags::SQLITE_OPEN_READ_WRITE,
10 )?;
11 conn.execute(
12 "CREATE TABLE IF NOT EXISTS urls (
13 link TEXT PRIMARY KEY,
14 shortlink TEXT NOT NULL
15 )",
16 NO_PARAMS,
17 )?;
18 return Ok(conn);
19}