mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 15:29:28 +01:00
5b2682aee2
Some checks are pending
Dev / migrate-boltdb (push) Blocked by required conditions
Dev / migrate-mysql (push) Blocked by required conditions
Dev / migrate-mariadb (push) Blocked by required conditions
Dev / migrate-postgres (push) Blocked by required conditions
Dev / integrate-boltdb (push) Blocked by required conditions
Dev / integrate-mysql (push) Blocked by required conditions
Dev / integrate-mariadb (push) Blocked by required conditions
Dev / integrate-postgres (push) Blocked by required conditions
Dev / deploy-server (push) Blocked by required conditions
Dev / deploy-runner (push) Blocked by required conditions
91 lines
2.0 KiB
Go
91 lines
2.0 KiB
Go
package sql
|
|
|
|
import (
|
|
"database/sql"
|
|
"github.com/Masterminds/squirrel"
|
|
"github.com/semaphoreui/semaphore/db"
|
|
)
|
|
|
|
func (d *SqlDb) CreateIntegrationAlias(alias db.IntegrationAlias) (res db.IntegrationAlias, err error) {
|
|
|
|
insertID, err := d.insert(
|
|
"id",
|
|
"insert into project__integration_alias (project_id, integration_id, alias) values (?, ?, ?)",
|
|
alias.ProjectID,
|
|
alias.IntegrationID,
|
|
alias.Alias)
|
|
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
res = alias
|
|
res.ID = insertID
|
|
return
|
|
}
|
|
|
|
func (d *SqlDb) GetIntegrationAliases(projectID int, integrationID *int) (res []db.IntegrationAlias, err error) {
|
|
|
|
q := squirrel.Select("*").From(db.IntegrationAliasProps.TableName)
|
|
|
|
if integrationID == nil {
|
|
q = q.Where("project_id=? AND integration_id is null", projectID)
|
|
} else {
|
|
q = q.Where("project_id=? AND integration_id=?", projectID, integrationID)
|
|
}
|
|
|
|
query, args, err := q.ToSql()
|
|
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
_, err = d.selectAll(&res, query, args...)
|
|
|
|
return
|
|
}
|
|
|
|
func (d *SqlDb) GetIntegrationsByAlias(alias string) (res []db.Integration, err error) {
|
|
|
|
var aliasObj db.IntegrationAlias
|
|
|
|
q := squirrel.Select("*").
|
|
From(db.IntegrationAliasProps.TableName).
|
|
Where("alias=?", alias)
|
|
|
|
query, args, err := q.ToSql()
|
|
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = d.selectOne(&aliasObj, query, args...)
|
|
|
|
if err == sql.ErrNoRows {
|
|
err = db.ErrNotFound
|
|
}
|
|
|
|
if aliasObj.IntegrationID == nil {
|
|
var projIntegrations []db.Integration
|
|
projIntegrations, err = d.GetIntegrations(aliasObj.ProjectID, db.RetrieveQueryParams{})
|
|
if err != nil {
|
|
return
|
|
}
|
|
for _, integration := range projIntegrations {
|
|
if integration.Searchable {
|
|
res = append(res, integration)
|
|
}
|
|
}
|
|
} else {
|
|
var integration db.Integration
|
|
integration, err = d.GetIntegration(aliasObj.ProjectID, *aliasObj.IntegrationID)
|
|
res = append(res, integration)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (d *SqlDb) DeleteIntegrationAlias(projectID int, aliasID int) error {
|
|
return d.deleteObject(projectID, db.IntegrationAliasProps, aliasID)
|
|
}
|