1
0
Fork 0
mirror of https://github.com/SinTan1729/chhoto-url synced 2025-04-28 11:56:52 -05:00

chg: Move the uniqueness validation to the INDEX

This commit is contained in:
Sayantan Santra 2025-04-19 19:31:43 -05:00
parent b2bc2c450b
commit 88ddb4299a
Signed by: SinTan1729
GPG key ID: 0538DD402EA50898

View file

@ -92,7 +92,7 @@ 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 UNIQUE, short_url TEXT NOT NULL,
hits INTEGER NOT NULL hits INTEGER NOT NULL
)", )",
[], [],
@ -101,7 +101,7 @@ pub fn open_db(path: String) -> Connection {
// Create index on short_url for faster lookups // Create index on short_url for faster lookups
db.execute( db.execute(
"CREATE INDEX IF NOT EXISTS idx_short_url ON urls (short_url)", "CREATE UNIQUE INDEX IF NOT EXISTS idx_short_url ON urls (short_url)",
[], [],
) )
.expect("Unable to create index on short_url."); .expect("Unable to create index on short_url.");