mirror of
https://gitlab.com/commento/commento.git
synced 2025-06-29 22:56:37 -04:00
api,db: add page attributes and thread locking
This commit is contained in:

committed by
Adhityaa Chandrasekar

parent
0a03a2c6fc
commit
299649cea2
34
api/page_get.go
Normal file
34
api/page_get.go
Normal file
@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func pageGet(domain string, path string) (page, error) {
|
||||
// path can be empty
|
||||
if domain == "" {
|
||||
return page{}, errorMissingField
|
||||
}
|
||||
|
||||
statement := `
|
||||
SELECT isLocked
|
||||
FROM pages
|
||||
WHERE domain=$1 AND path=$2;
|
||||
`
|
||||
row := db.QueryRow(statement, domain, path)
|
||||
|
||||
p := page{Domain: domain, Path: path}
|
||||
if err := row.Scan(&p.IsLocked); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
// If there haven't been any comments, there won't be a record for this
|
||||
// page. The sane thing to do is return defaults.
|
||||
// TODO: the defaults are hard-coded in two places: here and the schema
|
||||
p.IsLocked = false
|
||||
} else {
|
||||
logger.Errorf("error scanning page: %v", err)
|
||||
return page{}, errorInternal
|
||||
}
|
||||
}
|
||||
|
||||
return p, nil
|
||||
}
|
Reference in New Issue
Block a user