mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-02 19:05:32 -04:00
Add unique constraint to tags and error handling
This commit is contained in:
parent
40a24f4247
commit
0f1d1099f6
@ -36,7 +36,7 @@ class Storage
|
|||||||
DB.open "sqlite3://#{@path}" do |db|
|
DB.open "sqlite3://#{@path}" do |db|
|
||||||
begin
|
begin
|
||||||
# v0.18.0
|
# v0.18.0
|
||||||
db.exec "create table tags (id text, tag text)"
|
db.exec "create table tags (id text, tag text, unique (id, tag))"
|
||||||
db.exec "create index tags_id_idx on tags (id)"
|
db.exec "create index tags_id_idx on tags (id)"
|
||||||
db.exec "create index tags_tag_idx on tags (tag)"
|
db.exec "create index tags_tag_idx on tags (tag)"
|
||||||
|
|
||||||
@ -347,11 +347,17 @@ class Storage
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_tag(id : String, tag : String)
|
def add_tag(id : String, tag : String)
|
||||||
|
err = nil
|
||||||
MainFiber.run do
|
MainFiber.run do
|
||||||
get_db do |db|
|
begin
|
||||||
db.exec "insert into tags values (?, ?)", id, tag
|
get_db do |db|
|
||||||
|
db.exec "insert into tags values (?, ?)", id, tag
|
||||||
|
end
|
||||||
|
rescue e
|
||||||
|
err = e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
raise err.not_nil! if err
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_tag(id : String, tag : String)
|
def delete_tag(id : String, tag : String)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user