DEV.co
Open-Source Databases · georgysavva

scany

scany is a Go library that simplifies reading database query results into Go structs and other types without manual row iteration. It works with standard database/sql and the pgx driver, reducing boilerplate and error-prone code when working with databases directly.

Source: GitHub — github.com/georgysavva/scany
1.5k
GitHub stars
75
Forks
Go
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositorygeorgysavva/scany
Ownergeorgysavva
Primary languageGo
LicenseMIT — OSI-approved
Stars1.5k
Forks75
Open issues3
Latest releasev2.1.4 (2025-03-19)
Last updated2025-03-19
Sourcehttps://github.com/georgysavva/scany

What scany is

scany provides struct scanning, NULL handling, nested/embedded type support, and custom column mapping via struct tags. It operates as a data-mapping layer above database/sql and pgx, not an ORM—handling only result deserialization, not query generation or relationships.

Quickstart

Get the scany source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/georgysavva/scany.gitcd scany# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Direct SQL Workflows in Go Services

Teams that prefer writing raw SQL queries and need efficient, type-safe result mapping without ORM overhead. Common in microservices, APIs, and backend services where query control is a priority.

PostgreSQL-Heavy Applications

Applications using pgx for native PostgreSQL driver benefits (connection pooling, prepared statements) that need clean struct scanning without learning a full ORM.

Multi-Database Codebases

Projects that must support multiple database backends (MySQL, PostgreSQL, SQLite via database/sql) with a consistent scanning API and minimal vendor lock-in.

Implementation considerations

  • Struct field names and column names must align or be mapped via struct tags; mismatches will cause silent skip or errors depending on configuration.
  • NULL handling requires Pointer types or sql.NullType wrappers; ensure all nullable columns are properly typed to avoid scan failures.
  • Custom types (e.g., JSON, UUID, arrays) need custom Scan/Value methods or post-processing; scany delegates to the database driver's type support.
  • Query result order and column selection matter—scany maps by column name, not position, but performance depends on correct query design.
  • Error handling is critical: invalid struct definitions, type mismatches, or connection failures will bubble up as scan errors; callers must check and log appropriately.

When to avoid it — and what to weigh

  • Complex Entity Relationships Required — scany does not handle one-to-many, many-to-many, or other relational mapping. Projects needing automatic relationship loading should use a full ORM (e.g., GORM, ent).
  • Query Building Abstraction Needed — scany only scans results; it cannot generate SQL from structs. If dynamic query building, migrations, or schema management are required, an ORM is more appropriate.
  • Non-SQL Databases — scany is SQL-centric and integrates with database/sql or pgx. Projects using MongoDB, DynamoDB, or other NoSQL stores require alternative libraries.
  • High-Level Abstraction Preference — Teams that prefer minimal SQL writing and maximum framework automation should evaluate full ORMs instead of a scanning-only library.

License & commercial use

Licensed under MIT (permissive OSI license). Allows commercial use, modification, and distribution with minimal restrictions; only requires retention of the license notice and copyright.

MIT license permits commercial use without royalties or restrictions. No commercial support or warranty is stated in the project. For production use, confirm internal legal review and consider whether a commercial support contract is needed.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationAdequate
License clarityClear
Deployment complexityLow
DEV.co fitGood
Assessment confidenceHigh
Security considerations

scany itself is a mapping library with minimal attack surface. Security depends on the underlying database driver (database/sql or pgx) and query construction (always use parameterized queries to prevent SQL injection—scany does not generate queries). No known CVEs or security audit data provided.

Alternatives to consider

sqlx

More mature, database/sql-only alternative with similar scanning features. Wider adoption but less flexible for pgx users; different API design.

GORM

Full-featured ORM with query building, migrations, and relationship handling. Heavier, adds overhead, but solves more problems; overkill if only scanning is needed.

ent

Graph-based ORM with strong code generation and type safety. Opinionated schema-first approach; better for complex relationship modeling than scany.

Software development agency

Build on scany with DEV.co software developers

scany reduces boilerplate and errors in SQL result mapping. If your team prefers raw SQL with clean Go abstractions, evaluate scany for your next project or refactor.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

scany FAQ

Does scany generate SQL queries?
No. scany only scans (deserializes) results from executed queries. You must write and execute SQL manually or via another library. It is not an ORM.
Can I use scany with databases other than PostgreSQL and MySQL?
Yes, via database/sql driver support (SQLite, MSSQL, etc.) or by extending dbscan. See GitHub Wiki for integration patterns.
What happens if a struct field doesn't match a column name?
By default, scany skips the field. Use struct tags (e.g., `db:"column_name"`) to map non-matching names. Unmatched columns cause an error unless configured otherwise.
Is scany suitable for high-concurrency applications?
Yes, scany is stateless and thread-safe. Concurrency depends on the database driver and connection pool configuration, not scany itself.

Software development & web development with DEV.co

DEV.co helps companies turn open-source tools like scany into production software. Our software development services cover the full lifecycle — architecture, web development, integration, and maintenance — delivered by software developers and web developers who ship. Engage our software development agency to implement or customize it for your open-source databases stack.

Ready to streamline your Go database layer?

scany reduces boilerplate and errors in SQL result mapping. If your team prefers raw SQL with clean Go abstractions, evaluate scany for your next project or refactor.