-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
38 lines (31 loc) · 790 Bytes
/
list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package files
import "database/sql"
func List(db *sql.DB, folderId int64) ([]File, error) {
stmt := `SELECT * FROM files WHERE folder_id=$1 AND deleted=false`
rows, err := db.Query(stmt, folderId)
if err != nil {
return nil, err
}
return listFiles(rows), nil
}
func ListRoot(db *sql.DB) ([]File, error) {
stmt := `SELECT * FROM files WHERE folder_id IS NULL AND deleted=false`
rows, err := db.Query(stmt)
if err != nil {
return nil, err
}
return listFiles(rows), nil
}
func listFiles(rows *sql.Rows) []File {
files := make([]File, 0)
for rows.Next() {
var f File
err := rows.Scan(&f.ID, &f.FolderId, &f.OwnerId, &f.Name, &f.Type,
&f.Path, &f.CreatedAt, &f.ModifiedAt, &f.Deleted)
if err != nil {
continue
}
files = append(files, f)
}
return files
}