aboutsummaryrefslogtreecommitdiff
path: root/src/db.rs
diff options
context:
space:
mode:
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}