focalboard/server/services/store/sqlstore/sharing.go
Jesús Espino 2d261fde59
Adding mysql support to the database (#301)
* Adding mysql support

* Fixing other test cases

* Tests passing on mysql

* Fix the row number generation

* Adding blocks_history table

* merging the migrations in one single set of files

* Passing mysql tests

* Fixing default encoding on mysql

* Simplifying things

* Removing from the blocks table all deleted blocks

* Better indentation

* Moving db types to constants to make it less error prone

* reducing duplicated code

* Removing log line

* Now sql tests are running properly in mysql, sqlite and postgres
2021-04-22 22:53:01 +02:00

67 lines
1.4 KiB
Go

package sqlstore
import (
"time"
"github.com/mattermost/focalboard/server/model"
"github.com/mattermost/focalboard/server/services/store"
sq "github.com/Masterminds/squirrel"
)
func (s *SQLStore) UpsertSharing(c store.Container, sharing model.Sharing) error {
now := time.Now().Unix()
query := s.getQueryBuilder().
Insert(s.tablePrefix+"sharing").
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")
}
_, err := query.Exec()
return err
}
func (s *SQLStore) GetSharing(c store.Container, rootID string) (*model.Sharing, error) {
query := s.getQueryBuilder().
Select(
"id",
"enabled",
"token",
"modified_by",
"update_at",
).
From(s.tablePrefix + "sharing").
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
}