mirror of
https://github.com/nkanaev/yarr.git
synced 2025-09-13 09:55:36 +00:00
import opml
This commit is contained in:
@@ -13,17 +13,34 @@ type Folder struct {
|
||||
func (s *Storage) CreateFolder(title string) *Folder {
|
||||
expanded := true
|
||||
result, err := s.db.Exec(`
|
||||
insert into folders (title, is_expanded) values (?, ?)`,
|
||||
insert into folders (title, is_expanded) values (?, ?)
|
||||
on conflict (title) do nothing`,
|
||||
title, expanded,
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return nil
|
||||
}
|
||||
id, idErr := result.LastInsertId()
|
||||
if idErr != nil {
|
||||
|
||||
var id int64
|
||||
numrows, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return nil
|
||||
}
|
||||
if numrows == 1 {
|
||||
id, err = result.LastInsertId()
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
err = s.db.QueryRow(`select id, is_expanded from folders where title=?`, title).Scan(&id, &expanded)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return &Folder{Id: id, Title: title, IsExpanded: expanded}
|
||||
}
|
||||
|
||||
|
@@ -14,6 +14,8 @@ create table if not exists folders (
|
||||
is_expanded boolean not null default false
|
||||
);
|
||||
|
||||
create unique index if not exists idx_folder_title on folders(title);
|
||||
|
||||
create table if not exists feeds (
|
||||
id integer primary key autoincrement,
|
||||
folder_id references folders(id),
|
||||
@@ -63,12 +65,10 @@ func New() (*Storage, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
/*
|
||||
_, err = db.Exec(initQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
*/
|
||||
logger := log.New(os.Stdout, "storage: ", log.Ldate | log.Ltime | log.Lshortfile)
|
||||
return &Storage{db: db, log: logger}, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user