Skip to content

Commit

Permalink
feat: add a read only transaction helper (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr authored Oct 12, 2023
1 parent 4126131 commit 0e34bc4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions crdbx/readonly.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0

package crdbx

import (
"github.com/gobuffalo/pop/v6"

"github.com/ory/x/dbal"
"github.com/ory/x/sqlcon"
)

// SetTransactionReadOnly sets the transaction to read only for CockroachDB.
func SetTransactionReadOnly(c *pop.Connection) error {
if c.Dialect.Name() != dbal.DriverCockroachDB {
// Only CockroachDB supports this.
return nil
}

return sqlcon.HandleError(c.RawQuery("SET TRANSACTION READ ONLY").Exec())
}

0 comments on commit 0e34bc4

Please sign in to comment.