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

jmoiron / sqlx / 161
74%

Build:
DEFAULT BRANCH: master
Ran 20 Nov 2020 06:34PM UTC
Jobs 3
Files 7
Run time 13s
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

20 Nov 2020 04:44PM UTC coverage: 73.507% (+5.1%) from 68.365%
161

push

travis-ci

jmoiron
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

Jobs
ID Job ID Ran Files Coverage
1 161.1 20 Nov 2020 06:34PM UTC 0
73.51
Travis Job 161.1
2 161.2 20 Nov 2020 06:34PM UTC 0
73.51
Travis Job 161.2
3 161.3 20 Nov 2020 06:34PM UTC 0
73.51
Travis Job 161.3
Source Files on build 161
Detailed source file information is not available for this build.
  • Back to Repo
  • Travis Build #161
  • 00c6e74d on github
  • Prev Build on master (#155)
  • Next Build on master (#175)
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