From 367f939fee989d1cde9fe088eb7be61cb519fbe9 Mon Sep 17 00:00:00 2001 From: aeneasr <3372410+aeneasr@users.noreply.github.com> Date: Thu, 12 Oct 2023 14:48:48 +0200 Subject: [PATCH] feat: add read only transaction --- crdbx/readonly.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 crdbx/readonly.go diff --git a/crdbx/readonly.go b/crdbx/readonly.go new file mode 100644 index 00000000..ca551c72 --- /dev/null +++ b/crdbx/readonly.go @@ -0,0 +1,17 @@ +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()) +}