DATA-DOG/go-sqlmock

Sql mock driver for golang to test database interactions

View on GitHub ↗Jump to charts ↓

Summary Information

Updated 45 minutes ago
Added to GitGenius on September 10th, 2026
Created on February 7th, 2014
Open Issues & Pull Requests: 48 (+0)
GitHub issues: Enabled
Number of forks: 417
Total Stargazers: 6,572 (+0)
Total Subscribers: 51 (+0)

Repository Insights (GitGenius)

Median issue/PR response: 17.0 days
Mean response time: 177.5 days
90th percentile: 483.8 days
Tracked items: 17

Charts & Analytics

Fetching additional details & charts...

Issue Activity (beta)

Open issues: 12
New in 7 days: 0
Closed in 7 days: 0
Avg open age: 1,275 days
Stale 30+ days: 11
Stale 90+ days: 9

Recent activity

Opened in 7 days: 0
Closed in 7 days: 0
Comments in 7 days: 0
Events in 7 days: 0

Top labels

  • bug (2)
  • enhancement (1)

Most active issues this week

No issue events were indexed in the last 7 days.

Detailed Description

go-sqlmock is a mock library implementing the Go sql/driver interface to simulate database driver behavior in tests without requiring a real database connection.

The tool addresses the problem of testing database interactions in isolation by providing a mock SQL driver that intercepts database calls and allows you to define expected queries and their responses. It works by implementing the standard Go sql/driver interface, so it integrates directly with the database/sql package without requiring changes to your application code. The library supports concurrent access, multiple connections, Go context features, and named SQL parameters. It enforces strict expectation order matching by default and includes no third-party dependencies.

Developers should choose this tool when they want to test database logic in unit tests without spinning up a real database. It suits projects following test-driven development where you need to verify that your code issues the correct SQL queries and handles responses appropriately. The tool provides customizable query matching through a QueryMatcher interface, allowing you to match queries by exact equality, regular expression, or custom logic. For cases where you need to test with an actual database while keeping state isolated, the README mentions go-txdb as an alternative that wraps database operations in transactions.

The project is stable and complete, with the maintainer explicitly noting that few changes should be expected for this reason. The library supports concurrent operations and multiple simultaneous connections. It handles sophisticated argument matching for types like time.Time through an Argument interface when simple value comparison is insufficient.