mirror of
https://github.com/documize/community.git
synced 2025-08-04 21:15:24 +02:00
PostgreSQL prep
Update of vendored SQL libs and refactoring of store provider layer.
This commit is contained in:
parent
d0e005f638
commit
b455e5eaf5
105 changed files with 10949 additions and 2376 deletions
|
@ -15,21 +15,22 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/documize/community/core/env"
|
||||
"github.com/documize/community/domain"
|
||||
"github.com/documize/community/domain/store/mysql"
|
||||
"github.com/documize/community/domain/store"
|
||||
"github.com/documize/community/model/pin"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Scope provides data access to MySQL.
|
||||
type Scope struct {
|
||||
Runtime *env.Runtime
|
||||
// Store provides data access to user permission information.
|
||||
type Store struct {
|
||||
store.Context
|
||||
domain.PinStorer
|
||||
}
|
||||
|
||||
// Add saves pinned item.
|
||||
func (s Scope) Add(ctx domain.RequestContext, pin pin.Pin) (err error) {
|
||||
row := s.Runtime.Db.QueryRow("SELECT max(c_sequence) FROM dmz_pin WHERE c_orgid=? AND c_userid=?", ctx.OrgID, ctx.UserID)
|
||||
func (s Store) Add(ctx domain.RequestContext, pin pin.Pin) (err error) {
|
||||
row := s.Runtime.Db.QueryRow(s.Bind("SELECT max(c_sequence) FROM dmz_pin WHERE c_orgid=? AND c_userid=?"),
|
||||
ctx.OrgID, ctx.UserID)
|
||||
var maxSeq int
|
||||
err = row.Scan(&maxSeq)
|
||||
|
||||
|
@ -41,7 +42,7 @@ func (s Scope) Add(ctx domain.RequestContext, pin pin.Pin) (err error) {
|
|||
pin.Revised = time.Now().UTC()
|
||||
pin.Sequence = maxSeq + 1
|
||||
|
||||
_, err = ctx.Transaction.Exec("INSERT INTO dmz_pin (c_refid, c_orgid, c_userid, c_spaceid, c_docid, c_name, c_sequence, c_created, c_revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
_, err = ctx.Transaction.Exec(s.Bind("INSERT INTO dmz_pin (c_refid, c_orgid, c_userid, c_spaceid, c_docid, c_name, c_sequence, c_created, c_revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"),
|
||||
pin.RefID, pin.OrgID, pin.UserID, pin.SpaceID, pin.DocumentID, pin.Name, pin.Sequence, pin.Created, pin.Revised)
|
||||
|
||||
if err != nil {
|
||||
|
@ -52,12 +53,12 @@ func (s Scope) Add(ctx domain.RequestContext, pin pin.Pin) (err error) {
|
|||
}
|
||||
|
||||
// GetPin returns requested pinned item.
|
||||
func (s Scope) GetPin(ctx domain.RequestContext, id string) (pin pin.Pin, err error) {
|
||||
err = s.Runtime.Db.Get(&pin, `SELECT id, c_refid AS refid,
|
||||
func (s Store) GetPin(ctx domain.RequestContext, id string) (pin pin.Pin, err error) {
|
||||
err = s.Runtime.Db.Get(&pin, s.Bind(`SELECT id, c_refid AS refid,
|
||||
c_orgid AS orgid, c_userid AS userid, c_spaceid AS spaceid, c_docid AS documentid,
|
||||
c_name AS name, c_sequence AS sequence, c_created AS created, c_revised AS revised
|
||||
FROM dmz_pin
|
||||
WHERE c_orgid=? AND c_refid=?`,
|
||||
WHERE c_orgid=? AND c_refid=?`),
|
||||
ctx.OrgID, id)
|
||||
|
||||
if err != nil {
|
||||
|
@ -68,13 +69,13 @@ func (s Scope) GetPin(ctx domain.RequestContext, id string) (pin pin.Pin, err er
|
|||
}
|
||||
|
||||
// GetUserPins returns pinned items for specified user.
|
||||
func (s Scope) GetUserPins(ctx domain.RequestContext, userID string) (pins []pin.Pin, err error) {
|
||||
err = s.Runtime.Db.Select(&pins, `SELECT id, c_refid AS refid,
|
||||
func (s Store) GetUserPins(ctx domain.RequestContext, userID string) (pins []pin.Pin, err error) {
|
||||
err = s.Runtime.Db.Select(&pins, s.Bind(`SELECT id, c_refid AS refid,
|
||||
c_orgid AS orgid, c_userid AS userid, c_spaceid AS spaceid, c_docid AS documentid,
|
||||
c_name AS name, c_sequence AS sequence, c_created AS created, c_revised AS revised
|
||||
FROM dmz_pin
|
||||
WHERE c_orgid=? AND c_userid=?
|
||||
ORDER BY c_sequence`,
|
||||
ORDER BY c_sequence`),
|
||||
ctx.OrgID, userID)
|
||||
|
||||
if err != nil {
|
||||
|
@ -85,7 +86,7 @@ func (s Scope) GetUserPins(ctx domain.RequestContext, userID string) (pins []pin
|
|||
}
|
||||
|
||||
// UpdatePin updates existing pinned item.
|
||||
func (s Scope) UpdatePin(ctx domain.RequestContext, pin pin.Pin) (err error) {
|
||||
func (s Store) UpdatePin(ctx domain.RequestContext, pin pin.Pin) (err error) {
|
||||
pin.Revised = time.Now().UTC()
|
||||
|
||||
_, err = ctx.Transaction.NamedExec(`UPDATE dmz_pin SET
|
||||
|
@ -101,8 +102,8 @@ func (s Scope) UpdatePin(ctx domain.RequestContext, pin pin.Pin) (err error) {
|
|||
}
|
||||
|
||||
// UpdatePinSequence updates existing pinned item sequence number
|
||||
func (s Scope) UpdatePinSequence(ctx domain.RequestContext, pinID string, sequence int) (err error) {
|
||||
_, err = ctx.Transaction.Exec("UPDATE dmz_pin SET c_sequence=?, c_revised=? WHERE c_orgid=? AND c_userid=? AND c_refid=?",
|
||||
func (s Store) UpdatePinSequence(ctx domain.RequestContext, pinID string, sequence int) (err error) {
|
||||
_, err = ctx.Transaction.Exec(s.Bind("UPDATE dmz_pin SET c_sequence=?, c_revised=? WHERE c_orgid=? AND c_userid=? AND c_refid=?"),
|
||||
sequence, time.Now().UTC(), ctx.OrgID, ctx.UserID, pinID)
|
||||
|
||||
if err != nil {
|
||||
|
@ -113,19 +114,16 @@ func (s Scope) UpdatePinSequence(ctx domain.RequestContext, pinID string, sequen
|
|||
}
|
||||
|
||||
// DeletePin removes folder from the store.
|
||||
func (s Scope) DeletePin(ctx domain.RequestContext, id string) (rows int64, err error) {
|
||||
b := mysql.BaseQuery{}
|
||||
return b.DeleteConstrained(ctx.Transaction, "dmz_pin", ctx.OrgID, id)
|
||||
func (s Store) DeletePin(ctx domain.RequestContext, id string) (rows int64, err error) {
|
||||
return s.DeleteConstrained(ctx.Transaction, "dmz_pin", ctx.OrgID, id)
|
||||
}
|
||||
|
||||
// DeletePinnedSpace removes any pins for specified space.
|
||||
func (s Scope) DeletePinnedSpace(ctx domain.RequestContext, spaceID string) (rows int64, err error) {
|
||||
b := mysql.BaseQuery{}
|
||||
return b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_pin WHERE c_orgid=\"%s\" AND c_spaceid=\"%s\"", ctx.OrgID, spaceID))
|
||||
func (s Store) DeletePinnedSpace(ctx domain.RequestContext, spaceID string) (rows int64, err error) {
|
||||
return s.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_pin WHERE c_orgid=\"%s\" AND c_spaceid=\"%s\"", ctx.OrgID, spaceID))
|
||||
}
|
||||
|
||||
// DeletePinnedDocument removes any pins for specified document.
|
||||
func (s Scope) DeletePinnedDocument(ctx domain.RequestContext, documentID string) (rows int64, err error) {
|
||||
b := mysql.BaseQuery{}
|
||||
return b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_pin WHERE c_orgid=\"%s\" AND c_docid=\"%s\"", ctx.OrgID, documentID))
|
||||
func (s Store) DeletePinnedDocument(ctx domain.RequestContext, documentID string) (rows int64, err error) {
|
||||
return s.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_pin WHERE c_orgid=\"%s\" AND c_docid=\"%s\"", ctx.OrgID, documentID))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue