All Projects → georgysavva → Scany

georgysavva / Scany

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

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Scany

Sqlcheck
Automatically identify anti-patterns in SQL queries
Stars: ✭ 2,062 (+804.39%)
Mutual labels:  sql, database, mysql, postgresql
Eralchemy
Entity Relation Diagrams generation tool
Stars: ✭ 767 (+236.4%)
Mutual labels:  sql, database, mysql, postgresql
Go Sqlbuilder
A flexible and powerful SQL string builder library plus a zero-config ORM.
Stars: ✭ 539 (+136.4%)
Mutual labels:  sql, database, mysql, postgresql
Linq2db
Linq to database provider.
Stars: ✭ 2,211 (+869.74%)
Mutual labels:  sql, database, mysql, postgresql
Shardingsphere
Build criterion and ecosystem above multi-model databases
Stars: ✭ 14,989 (+6474.12%)
Mutual labels:  sql, database, mysql, postgresql
Qb
The database toolkit for go
Stars: ✭ 524 (+129.82%)
Mutual labels:  sql, database, mysql, postgresql
Db Dumper
Dump the contents of a database
Stars: ✭ 744 (+226.32%)
Mutual labels:  sql, database, mysql, postgresql
Franchise
🍟 a notebook sql client. what you get when have a lot of sequels.
Stars: ✭ 3,823 (+1576.75%)
Mutual labels:  sql, database, mysql, postgresql
Electrocrud
Database CRUD Application Built on Electron | MySQL, Postgres, SQLite
Stars: ✭ 1,267 (+455.7%)
Mutual labels:  sql, database, mysql, postgresql
Graphjin
GraphJin - Build APIs in 5 minutes with GraphQL. An instant GraphQL to SQL compiler.
Stars: ✭ 1,264 (+454.39%)
Mutual labels:  sql, database, mysql, postgresql
Db
Data access layer for PostgreSQL, CockroachDB, MySQL, SQLite and MongoDB with ORM-like features.
Stars: ✭ 2,832 (+1142.11%)
Mutual labels:  sql, database, mysql, postgresql
Kangaroo
SQL client and admin tool for popular databases
Stars: ✭ 127 (-44.3%)
Mutual labels:  sql, database, mysql, postgresql
Evolve
Database migration tool for .NET and .NET Core projects. Inspired by Flyway.
Stars: ✭ 477 (+109.21%)
Mutual labels:  sql, database, mysql, postgresql
Nut
Advanced, Powerful and easy to use ORM for Qt
Stars: ✭ 181 (-20.61%)
Mutual labels:  sql, database, mysql, postgresql
Jooq
jOOQ is the best way to write SQL in Java
Stars: ✭ 4,695 (+1959.21%)
Mutual labels:  sql, database, mysql, postgresql
Beekeeper Studio
Modern and easy to use SQL client for MySQL, Postgres, SQLite, SQL Server, and more. Linux, MacOS, and Windows.
Stars: ✭ 8,053 (+3432.02%)
Mutual labels:  sql, database, mysql, postgresql
Jet
Type safe SQL builder with code generation and automatic query result data mapping
Stars: ✭ 373 (+63.6%)
Mutual labels:  sql, database, mysql, postgresql
Dbeaver
Free universal database tool and SQL client
Stars: ✭ 23,752 (+10317.54%)
Mutual labels:  sql, database, mysql, postgresql
Goqu
SQL builder and query library for golang
Stars: ✭ 984 (+331.58%)
Mutual labels:  sql, database, mysql, postgresql
Qtl
A friendly and lightweight C++ database library for MySQL, PostgreSQL, SQLite and ODBC.
Stars: ✭ 92 (-59.65%)
Mutual labels:  sql, database, mysql, postgresql

scany

Build Status Go Report Card codecov PkgGoDev Mentioned in Awesome Go

Overview

Go favors simplicity, and it's pretty common to work with a database via driver directly without any ORM. It provides great control and efficiency in your queries, but here is a problem: you need to manually iterate over database rows and scan data from all columns into a corresponding destination. It can be error-prone verbose and just tedious. scany aims to solve this problem, 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.

Note that, scany isn't an ORM. First of all, it works only in one direction: it scans data into Go objects from the database, but it can't build database queries based on those objects. Secondly, it doesn't know anything about relations between objects e.g: one to many, many to many.

Features

  • Custom database column name via struct tag
  • Reusing structs via nesting or embedding
  • NULLs and custom types support
  • Omitted struct fields
  • Apart from structs, support for other destination types: maps, slices and etc.

Install

go get github.com/georgysavva/scany

How to use with database/sql

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.
}

Use sqlscan package to work with database/sql standard library.

How to use with pgx native interface

package main

import (
	"context"

	"github.com/jackc/pgx/v4/pgxpool"

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

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

func main() {
	ctx := context.Background()
	db, _ := pgxpool.Connect(ctx, "example-connection-url")

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

Use pgxscan package to work with pgx library native interface.

How to use with other database libraries

Use dbscan package that works with an abstract database, and can be integrated with any library that has a concept of rows. This particular package implements core scany features and contains all the logic. Both sqlscan and pgxscan use dbscan internally.

Comparisson with sqlx

  • sqlx only works with database/sql standard library. scany isn't limited only to database/sql, it also supports pgx native interface and can be extended to work with any database library independent of database/sql
  • In terms of scanning and mapping abilities, scany provides all features of sqlx
  • scany has a simpler API and much fewer concepts, so it's easier to start working with

Supported Go versions

scany supports Go 1.13 and higher.

Roadmap

  • Add ability to set custom function to translate struct field to column name, instead of the default to snake case function
  • Allow to use a custom separator for embedded structs prefix, instead of the default "."

Tests

The only thing you need to run tests locally is an internet connection, it's required to download and cache the database binary. Just type go test ./... inside scany root directory and let the code do the rest.

Contributing

Every feature request or question is appreciated. Don't hesitate, just post an issue or PR.

License

This project is licensed under the terms of the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].