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:
parent
b2bc2c450b
commit
88ddb4299a
1 changed files with 2 additions and 2 deletions
|
@ -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.");
|
||||||
|
|
Loading…
Reference in a new issue