mirror of
https://github.com/openziti/zrok.git
synced 2025-08-15 18:42:32 +02:00
changes to support the agreement between sqlite and postgres (#46)
This commit is contained in:
@ -15,31 +15,27 @@ type Environment struct {
|
||||
}
|
||||
|
||||
func (self *Store) CreateEnvironment(accountId int, i *Environment, tx *sqlx.Tx) (int, error) {
|
||||
stmt, err := tx.Prepare("insert into environments (account_id, description, host, address, z_id) values (?, ?, ?, ?, ?)")
|
||||
stmt, err := tx.Prepare("insert into environments (account_id, description, host, address, z_id) values ($1, $2, $3, $4, $5) returning id")
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "error preparing environments insert statement")
|
||||
}
|
||||
res, err := stmt.Exec(accountId, i.Description, i.Host, i.Address, i.ZId)
|
||||
if err != nil {
|
||||
var id int
|
||||
if err := stmt.QueryRow(accountId, i.Description, i.Host, i.Address, i.ZId).Scan(&id); err != nil {
|
||||
return 0, errors.Wrap(err, "error executing environments insert statement")
|
||||
}
|
||||
id, err := res.LastInsertId()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "error retrieving last environments insert id")
|
||||
}
|
||||
return int(id), nil
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (self *Store) GetEnvironment(id int, tx *sqlx.Tx) (*Environment, error) {
|
||||
i := &Environment{}
|
||||
if err := tx.QueryRowx("select * from environments where id = ?", id).StructScan(i); err != nil {
|
||||
if err := tx.QueryRowx("select * from environments where id = $1", id).StructScan(i); err != nil {
|
||||
return nil, errors.Wrap(err, "error selecting environment by id")
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (self *Store) FindEnvironmentsForAccount(accountId int, tx *sqlx.Tx) ([]*Environment, error) {
|
||||
rows, err := tx.Queryx("select environments.* from environments where account_id = ?", accountId)
|
||||
rows, err := tx.Queryx("select environments.* from environments where account_id = $1", accountId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error selecting environments by account id")
|
||||
}
|
||||
@ -55,7 +51,7 @@ func (self *Store) FindEnvironmentsForAccount(accountId int, tx *sqlx.Tx) ([]*En
|
||||
}
|
||||
|
||||
func (self *Store) DeleteEnvironment(id int, tx *sqlx.Tx) error {
|
||||
stmt, err := tx.Prepare("delete from environments where id = ?")
|
||||
stmt, err := tx.Prepare("delete from environments where id = $1")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error preparing environments delete statement")
|
||||
}
|
||||
|
Reference in New Issue
Block a user