Scany: Library for scanning data from a database into Go structs and more

Hi. I created this library: https://github.com/georgysavva/scany.
It allows developers to scan complex data from a database into Go structs and other composite types with just one function call and don’t bother with rows iteration.

scany isn’t limited to any specific database. It integrates with database/sql, so any database with database/sql driver is supported. It also works with pgx library native interface. Apart from the out of the box support, scany can be easily extended to work with almost any database library.

Here is how to use it:

package main

import (
	"context"
	"database/sql"

	"github.com/georgysavva/scany/sqlscan"
)

type User struct {
	ID    string
	Name  string
	Email string
	Age   int
}

func main() {
	ctx := context.Background()
	db, _ := sql.Open("postgres", "example-connection-url")

	var users []*User
	sqlscan.Select(ctx, db, &users, `SELECT id, name, email, age FROM users`)
	// users variable now contains data from all rows.
}

The library is feature-rich, well documented and tested.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.