1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-27 13:48:52 +02:00
focalboard/server/services/store/sqlstore/sharing.go

68 lines
1.4 KiB
Go
Raw Normal View History

2021-01-13 01:35:30 +02:00
package sqlstore
import (
"time"
2021-01-27 00:13:46 +02:00
"github.com/mattermost/focalboard/server/model"
2021-03-26 20:01:54 +02:00
"github.com/mattermost/focalboard/server/services/store"
2021-01-13 01:35:30 +02:00
sq "github.com/Masterminds/squirrel"
)
2021-03-26 20:01:54 +02:00
func (s *SQLStore) UpsertSharing(c store.Container, sharing model.Sharing) error {
2021-01-13 01:35:30 +02:00
now := time.Now().Unix()
query := s.getQueryBuilder().
2021-04-17 09:06:57 +02:00
Insert(s.tablePrefix+"sharing").
2021-01-13 01:35:30 +02:00
Columns(
"id",
"enabled",
"token",
"modified_by",
"update_at",
).
Values(
sharing.ID,
sharing.Enabled,
sharing.Token,
sharing.ModifiedBy,
now,
)
if s.dbType == mysqlDBType {
query = query.Suffix("ON DUPLICATE KEY UPDATE enabled = ?, token = ?, modified_by = ?, update_at = ?", sharing.Enabled, sharing.Token, sharing.ModifiedBy, now)
} else {
query = query.Suffix("ON CONFLICT (id) DO UPDATE SET enabled = EXCLUDED.enabled, token = EXCLUDED.token, modified_by = EXCLUDED.modified_by, update_at = EXCLUDED.update_at")
}
2021-01-13 01:35:30 +02:00
_, err := query.Exec()
return err
}
2021-03-26 20:01:54 +02:00
func (s *SQLStore) GetSharing(c store.Container, rootID string) (*model.Sharing, error) {
2021-01-13 01:35:30 +02:00
query := s.getQueryBuilder().
Select(
"id",
"enabled",
"token",
"modified_by",
"update_at",
).
2021-04-17 09:06:57 +02:00
From(s.tablePrefix + "sharing").
2021-01-13 01:35:30 +02:00
Where(sq.Eq{"id": rootID})
row := query.QueryRow()
sharing := model.Sharing{}
err := row.Scan(
&sharing.ID,
&sharing.Enabled,
&sharing.Token,
&sharing.ModifiedBy,
&sharing.UpdateAt,
)
if err != nil {
return nil, err
}
return &sharing, nil
}