mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
sqlite on delete actions
This commit is contained in:
parent
7560b8167b
commit
a850d83b33
@ -58,9 +58,11 @@ func (s *Storage) CreateFeed(title, description, link, feedLink string, folderId
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) DeleteFeed(feedId int64) bool {
|
func (s *Storage) DeleteFeed(feedId int64) bool {
|
||||||
_, err1 := s.db.Exec(`delete from items where feed_id = ?`, feedId)
|
_, err := s.db.Exec(`delete from feeds where id = ?`, feedId)
|
||||||
_, err2 := s.db.Exec(`delete from feeds where id = ?`, feedId)
|
if err != nil {
|
||||||
return err1 == nil && err2 == nil
|
s.log.Print(err)
|
||||||
|
}
|
||||||
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) RenameFeed(feedId int64, newTitle string) bool {
|
func (s *Storage) RenameFeed(feedId int64, newTitle string) bool {
|
||||||
|
@ -45,9 +45,11 @@ func (s *Storage) CreateFolder(title string) *Folder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) DeleteFolder(folderId int64) bool {
|
func (s *Storage) DeleteFolder(folderId int64) bool {
|
||||||
_, err1 := s.db.Exec(`update feeds set folder_id = null where folder_id = ?`, folderId)
|
_, err := s.db.Exec(`delete from folders where id = ?`, folderId)
|
||||||
_, err2 := s.db.Exec(`delete from folders where id = ?`, folderId)
|
if err != nil {
|
||||||
return err1 == nil && err2 == nil
|
s.log.Print(err)
|
||||||
|
}
|
||||||
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) RenameFolder(folderId int64, newTitle string) bool {
|
func (s *Storage) RenameFolder(folderId int64, newTitle string) bool {
|
||||||
|
@ -301,6 +301,7 @@ func HTMLText(s string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Storage) SyncSearch() {
|
func (s *Storage) SyncSearch() {
|
||||||
|
// TODO: cleaning up once feeds/items are deleted?
|
||||||
rows, err := s.db.Query(`
|
rows, err := s.db.Query(`
|
||||||
select id, title, content, description
|
select id, title, content, description
|
||||||
from items
|
from items
|
||||||
|
@ -18,7 +18,7 @@ create unique index if not exists idx_folder_title on folders(title);
|
|||||||
|
|
||||||
create table if not exists feeds (
|
create table if not exists feeds (
|
||||||
id integer primary key autoincrement,
|
id integer primary key autoincrement,
|
||||||
folder_id references folders(id),
|
folder_id references folders(id) on delete set null,
|
||||||
title text not null,
|
title text not null,
|
||||||
description text,
|
description text,
|
||||||
link text,
|
link text,
|
||||||
@ -32,7 +32,7 @@ create unique index if not exists idx_feed_feed_link on feeds(feed_link);
|
|||||||
create table if not exists items (
|
create table if not exists items (
|
||||||
id integer primary key autoincrement,
|
id integer primary key autoincrement,
|
||||||
guid string not null,
|
guid string not null,
|
||||||
feed_id references feeds(id),
|
feed_id references feeds(id) on delete cascade,
|
||||||
title text,
|
title text,
|
||||||
link text,
|
link text,
|
||||||
description text,
|
description text,
|
||||||
@ -63,7 +63,7 @@ create trigger if not exists del_item_search after delete on items begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
create table if not exists http_states (
|
create table if not exists http_states (
|
||||||
feed_id references feeds(id) unique,
|
feed_id references feeds(id) on delete cascade unique,
|
||||||
last_refreshed datetime not null,
|
last_refreshed datetime not null,
|
||||||
|
|
||||||
-- http header fields --
|
-- http header fields --
|
||||||
@ -72,7 +72,7 @@ create table if not exists http_states (
|
|||||||
);
|
);
|
||||||
|
|
||||||
create table if not exists feed_errors (
|
create table if not exists feed_errors (
|
||||||
feed_id references feeds(id) unique,
|
feed_id references feeds(id) on delete cascade unique,
|
||||||
error string
|
error string
|
||||||
);
|
);
|
||||||
`
|
`
|
||||||
@ -96,6 +96,7 @@ func New(path string, logger *log.Logger) (*Storage, error) {
|
|||||||
|
|
||||||
db.SetMaxOpenConns(1)
|
db.SetMaxOpenConns(1)
|
||||||
|
|
||||||
|
// TODO: migration for 'on delete' actions
|
||||||
if _, err := db.Exec(initQuery); err != nil {
|
if _, err := db.Exec(initQuery); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user