• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nildeps / sqlx
74%

Build:
DEFAULT BRANCH: master
Repo Added 06 Jan 2021 08:08PM UTC
Files 7
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

LAST BUILD ON BRANCH master
branch: master
CHANGE BRANCH
x
Reset
  • master
  • v1.2.0

06 Jan 2021 08:27PM UTC coverage: 73.507%. First build
1

push

travis-ci

condemil
allow users to specify bind type (#520)

This is a thread-safe implementation of #520, which adds a single
function `sqlx.BindDriver(driverName string, bindType int)` that allows
users of sqlx to specify the bind type for any driver.

This allows rebinding, and therefore named queries, to work in a lot
more cases:

* a new driver is released but not yet catalogued in SQLX
* users customize a driver and give it a new name

To do this, a registry had to be created so that it could be updated at
runtime.  This represents a synchronization problem, as it would be
written to and read from after compile time.  I tried two approaches:

* use `sync.Map`
* use `atomic.Value` and load/store the registry

Details within, but `sync.Map` ended up being 5x slower, and the
`atomic.Value` approach was ~2.5x slower:

```
goos: linux
goarch: amd64
pkg: github.com/jmoiron/sqlx

original:
BenchmarkBindSpeed/old-4                100000000               11.0 ns/op

sync.Map:
BenchmarkBindSpeed/new-4                24575726                50.8 ns/op

atomic.Value
BenchmarkBindSpeed/new-4                42535839                27.5 ns/op
```

Despite the slower showing, using `atomic.Value` in this way has
a correctness tradeoff.  Loads and Stores are guaranteed to be atomic,
but using Load+Store means that in cases of simultaneous writes, a write
could get lost.  This would be a _very_ difficult bug to find, so I've
opted for `sync.Map` despite the worse performance.

I think this is an acceptable trade-off as this is really unlikely to be
in any hot loops.

If this performance degredation does become a problem, another option
would be to hardcode the original registry in a switch as in the original
implementation, and only fallback on the custom registry.  I don't know
of a use case where people would want to _change_ the bindtype of a
driver whose bindtype is already known, but the flexibility seems worth
it as the performance lost doesn't seem like it's important.

11 of 11 new or added lines in 1 file covered. (100.0%)

1182 of 1608 relevant lines covered (73.51%)

590.17 hits per line

Relevant lines Covered
Build:
Build:
1608 RELEVANT LINES 1182 COVERED LINES
590.17 HITS PER LINE
Source Files on master
  • Tree
  • List 7
  • Changed 0
  • Source Changed 0
  • Coverage Changed 0
Coverage ∆ File Lines Relevant Covered Missed Hits/Line

Recent builds

Builds Branch Commit Type Ran Committer Via Coverage
1 master allow users to specify bind type (#520) This is a thread-safe implementation of #520, which adds a single function `sqlx.BindDriver(driverName string, bindType int)` that allows users of sqlx to specify the bind type for any driver. This allows ... push 06 Jan 2021 08:49PM UTC condemil travis-ci
73.51
See All Builds (2)
  • Repo on GitHub
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc