diff --git a/server/channels/store/sqlstore/outgoing_oauth_connection_store.go b/server/channels/store/sqlstore/outgoing_oauth_connection_store.go index 6c4db24457..398f6ad60c 100644 --- a/server/channels/store/sqlstore/outgoing_oauth_connection_store.go +++ b/server/channels/store/sqlstore/outgoing_oauth_connection_store.go @@ -17,10 +17,20 @@ import ( type SqlOutgoingOAuthConnectionStore struct { *SqlStore + + tableSelectQuery sq.SelectBuilder } func newSqlOutgoingOAuthConnectionStore(sqlStore *SqlStore) store.OutgoingOAuthConnectionStore { - return &SqlOutgoingOAuthConnectionStore{sqlStore} + s := SqlOutgoingOAuthConnectionStore{ + SqlStore: sqlStore, + } + + s.tableSelectQuery = s.getQueryBuilder(). + Select("Id", "CreatorId", "CreateAt", "UpdateAt", "Name", "ClientId", "ClientSecret", "CredentialsUsername", "CredentialsPassword", "OAuthTokenURL", "GrantType", "Audiences"). + From("OutgoingOAuthConnections") + + return &s } func (s *SqlOutgoingOAuthConnectionStore) SaveConnection(c request.CTX, conn *model.OutgoingOAuthConnection) (*model.OutgoingOAuthConnection, error) { @@ -86,7 +96,9 @@ func (s *SqlOutgoingOAuthConnectionStore) UpdateConnection(c request.CTX, conn * func (s *SqlOutgoingOAuthConnectionStore) GetConnection(c request.CTX, id string) (*model.OutgoingOAuthConnection, error) { conn := &model.OutgoingOAuthConnection{} - if err := s.GetReplica().Get(conn, `SELECT * FROM OutgoingOAuthConnections WHERE Id=?`, id); err != nil { + query := s.tableSelectQuery.Where(sq.Eq{"Id": id}) + + if err := s.GetReplica().GetBuilder(conn, query); err != nil { if err == sql.ErrNoRows { return nil, store.NewErrNotFound("OutgoingOAuthConnection", id) } @@ -99,11 +111,7 @@ func (s *SqlOutgoingOAuthConnectionStore) GetConnections(c request.CTX, filters filters.SetDefaults() conns := []*model.OutgoingOAuthConnection{} - query := s.getQueryBuilder(). - Select("*"). - From("OutgoingOAuthConnections"). - OrderBy("Id"). - Limit(uint64(filters.Limit)) + query := s.tableSelectQuery.OrderBy("Id").Limit(uint64(filters.Limit)) if filters.OffsetId != "" { query = query.Where("Id > ?", filters.OffsetId)