1
0
Fork 0
mirror of https://github.com/SinTan1729/chhoto-url synced 2025-04-19 19:30:01 -05:00

add unique constraint and create index on short URL

This commit is contained in:
Magnus 2025-04-18 20:26:29 +02:00
parent d198135144
commit b2bc2c450b

View file

@ -92,12 +92,19 @@ pub fn open_db(path: String) -> Connection {
"CREATE TABLE IF NOT EXISTS urls ( "CREATE TABLE IF NOT EXISTS urls (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
long_url TEXT NOT NULL, long_url TEXT NOT NULL,
short_url TEXT NOT NULL, short_url TEXT NOT NULL UNIQUE,
hits INTEGER NOT NULL hits INTEGER NOT NULL
)", )",
[], [],
) )
.expect("Unable to initialize empty database."); .expect("Unable to initialize empty database.");
// Create index on short_url for faster lookups
db.execute(
"CREATE INDEX IF NOT EXISTS idx_short_url ON urls (short_url)",
[],
)
.expect("Unable to create index on short_url.");
db db
} }