From fcab58ca53ad1904f1c3ccf6a5bd8b54c6a5391c Mon Sep 17 00:00:00 2001
From: Kirill Smelkov <kirr@nexedi.com>
Date: Tue, 2 Oct 2018 12:21:49 +0300
Subject: [PATCH] go/zodb: Connection += .At()

To know database state corresponding to the connection.
---
 go/zodb/connection.go | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/go/zodb/connection.go b/go/zodb/connection.go
index da705ede..59188db1 100644
--- a/go/zodb/connection.go
+++ b/go/zodb/connection.go
@@ -130,6 +130,12 @@ func newConnection(db *DB, at Tid) *Connection {
 	}
 }
 
+// At returns database state corresponding to the connection.
+func (conn *Connection) At() Tid {
+	conn.checkLive("at")
+	return conn.at
+}
+
 // wrongClassError is the error cause returned when ZODB object's class is not what was expected.
 type wrongClassError struct {
 	want, have string
@@ -238,3 +244,11 @@ func (conn *Connection) checkTxn(txn transaction.Transaction, who string) {
 		panic("connection: " + who + "current transaction is different from connection transaction")
 	}
 }
+
+// checkLive asserts that the connection is alive - the transaction under which
+// it has been opened is not yet complete.
+func (conn *Connection) checkLive(who string) {
+	if conn.txn == nil {
+		panic("connection: " + who + ": connection is not live")
+	}
+}
-- 
2.30.9