Пример #1
0
		Expect(err).To(MatchError("disaster"))
	})

	Describe("query counting", func() {
		It("increments the global (;_;) counter", func() {
			_, err := countingConn.Query("SELECT $1::int", 1)
			Expect(err).NotTo(HaveOccurred())

			Expect(metric.DatabaseQueries.Max()).To(Equal(1))

			_, err = countingConn.Exec("SELECT $1::int", 1)
			Expect(err).NotTo(HaveOccurred())

			Expect(metric.DatabaseQueries.Max()).To(Equal(2))

			countingConn.QueryRow("SELECT $1::int", 1)

			Expect(metric.DatabaseQueries.Max()).To(Equal(3))

			By("working in transactions")
			underlyingTx := &fakes.FakeTx{}
			underlyingConn.BeginReturns(underlyingTx, nil)

			tx, err := countingConn.Begin()
			Expect(err).NotTo(HaveOccurred())

			_, err = tx.Query("SELECT $1::int", 1)
			Expect(err).NotTo(HaveOccurred())

			Expect(metric.DatabaseQueries.Max()).To(Equal(4))
		})
Пример #2
0
				rows, err := explainConn.Query("SELECT $1::int", 1)
				Ω(err).ShouldNot(HaveOccurred())

				err = rows.Close()
				Ω(err).ShouldNot(HaveOccurred())

				Expect(logger).To(gbytes.Say("Result"))
				Expect(logger).To(gbytes.Say("cost="))
				Expect(logger).To(gbytes.Say("SELECT"))
			})
		})

		Describe("QueryRow()", func() {
			It("EXPLAINs the query", func() {
				var i int
				err := explainConn.QueryRow("SELECT $1::int", 1).Scan(&i)
				Ω(err).ShouldNot(HaveOccurred())

				Ω(underlyingConn.QueryRowCallCount()).Should(Equal(1))
				Ω(underlyingConn.QueryCallCount()).Should(Equal(1))

				query, args := underlyingConn.QueryRowArgsForCall(0)
				Ω(query).Should(Equal("SELECT $1::int"))
				Ω(args).Should(Equal(varargs(1)))

				query, args = underlyingConn.QueryArgsForCall(0)
				Ω(query).Should(Equal("EXPLAIN SELECT $1::int"))
				Ω(args).Should(Equal(varargs(1)))
			})

			It("logs the output of the explain", func() {