Golang REST Layer SQL Storage Handler

Golang REST Layer SQL Storage Handler

This REST Layer resource storage backend stores data in a SQL Database using database/sql.

Usage

import "github.com/Hyper38/rest-layer-sql"

Create a resource storage handler with a given SQL driver, source and table:

h := sqlStorage.NewHandler(DB_DRIVER, DB_SOURCE, DB_TABLE)

Bind this resource storage handled to a resource:

index.Bind("resourceName", resourceSchema, h, resource.DefaultConf)

Supported SQL Drivers

All supported SQL Drivers are listed here

Examples

Run the example:

$ go run example/example.go
2018/12/07 18:29:53 Serving API on http://localhost:8080

You can perform requests using HTTPie.

$ http GET :8080/units
HTTP/1.1 200 OK
Content-Length: 2
Content-Type: application/json
Date: Fri, 07 Dec 2018 17:31:23 GMT
Etag: W/"d41d8cd98f00b204e9800998ecf8427e"
X-Total: 0

[]

$ http POST :8080/units str="foo" int:=0
HTTP/1.1 201 Created
Content-Length: 139
Content-Location: /units/bg5at5bmvban389193a0
Content-Type: application/json
Date: Fri, 07 Dec 2018 17:32:05 GMT
Etag: W/"80b0d96e674f761e87950ccb19bdc279"
Last-Modified: Fri, 07 Dec 2018 17:32:05 GMT

{
    "created": "2018-12-07T18:32:05.290925+01:00",
    "id": "bg5at5bmvban389193a0",
    "int": 0,
    "str": "foo",
    "updated": "2018-12-07T18:32:05.290925+01:00"
}

$ http POST :8080/units str="bar" int:=1
HTTP/1.1 201 Created
Content-Length: 137
Content-Location: /units/bg5at73mvban389193ag
Content-Type: application/json
Date: Fri, 07 Dec 2018 17:32:12 GMT
Etag: W/"8bb72222f5979bc9f9259c0262807667"
Last-Modified: Fri, 07 Dec 2018 17:32:12 GMT

{
    "created": "2018-12-07T18:32:12.08373+01:00",
    "id": "bg5at73mvban389193ag",
    "int": 1,
    "str": "bar",
    "updated": "2018-12-07T18:32:12.08373+01:00"
}

$ http GET :8080/units
HTTP/1.1 200 OK
Content-Length: 365
Content-Type: application/json
Date: Fri, 07 Dec 2018 17:32:44 GMT
Etag: W/"0a320d03fee8e1fb268d3cc48fac391d"
X-Total: 0

[
    {
        "_etag": "80b0d96e674f761e87950ccb19bdc279",
        "created": "2018-12-07T18:32:05.290925+01:00",
        "id": "bg5at5bmvban389193a0",
        "int": 0,
        "str": "foo",
        "updated": "2018-12-07T18:32:05.290925+01:00"
    },
    {
        "_etag": "8bb72222f5979bc9f9259c0262807667",
        "created": "2018-12-07T18:32:12.08373+01:00",
        "id": "bg5at73mvban389193ag",
        "int": 1,
        "str": "bar",
        "updated": "2018-12-07T18:32:12.08373+01:00"
    }
]
Similar Resources

SQL transaction wrapper on golang

TxWrapper TxWrapper is a sql transaction wrapper. It helps to exclude writing code for rollback and commit commands. Usage import ( "context"

Mar 14, 2022

Simple SQL escape and format for golang

sqlstring Simple SQL escape and format Escaping sql values //Format sql := sqlstring.Format("select * from users where name=? and age=? limit ?,?", "t

Sep 4, 2022

BigQuery database/sql golang driver

BigQuery SQL Driver This library is compatible with Go 1.17+ Please refer to CHA

Dec 7, 2022

Spansqlx - Spanner sql pkgs with golang

spansqlx spanner sql pkgs install go get github.com/reiot777/spansqlx usage Bel

Jan 15, 2022

A MySQL-compatible relational database with a storage agnostic query engine. Implemented in pure Go.

go-mysql-server go-mysql-server is a SQL engine which parses standard SQL (based on MySQL syntax) and executes queries on data sources of your choice.

Jan 2, 2023

Jaeger ClickHouse storage plugin implementation

Jaeger ClickHouse Jaeger ClickHouse gRPC storage plugin. This is WIP and it is based on https://github.com/bobrik/jaeger/tree/ivan/clickhouse/plugin/s

Feb 15, 2022

MySQL Storage engine conversion,Support mutual conversion between MyISAM and InnoDB engines.

econvert MySQL Storage engine conversion 简介 此工具用于MySQL存储引擎转换,支持CTAS和ALTER两种模式,目前只支持MyISAM和InnoDB存储引擎相互转换,其它引擎尚不支持。 注意:当对表进行引擎转换时,建议业务停止访问或者极少量访问时进行。 原

Oct 25, 2021

Linux GUI viewer for ZFS pool, dataset and host storage.

Linux GUI viewer for ZFS pool, dataset and host storage.

This is a WIP in alpha stage. zgui Linux GUI viewer for ZFS pool, dataset and host storage. zgui used libzfs directly and not ZFS command line tools.

Dec 7, 2021

Go package for sharding databases ( Supports every ORM or raw SQL )

Go package for sharding databases ( Supports every ORM or raw SQL )

Octillery Octillery is a Go package for sharding databases. It can use with every OR Mapping library ( xorm , gorp , gorm , dbr ...) implementing data

Dec 16, 2022
Parses a file and associate SQL queries to a map. Useful for separating SQL from code logic

goyesql This package is based on nleof/goyesql but is not compatible with it any more. This package introduces support for arbitrary tag types and cha

Oct 20, 2021
Go-sql-reader - Go utility to read the externalised sql with predefined tags

go-sql-reader go utility to read the externalised sql with predefined tags Usage

Jan 25, 2022
A go package to add support for data at rest encryption if you are using the database/sql.

go-lockset A go package to add support for data at rest encryption if you are using the database/sql to access your database. Installation In your Gol

Jan 30, 2022
Database Access Layer for Golang - Testable, Extendable and Crafted Into a Clean and Elegant API

REL Modern Database Access Layer for Golang. REL is golang orm-ish database layer for layered architecture. It's testable and comes with its own test

Dec 29, 2022
Sqlair - SQLite Query Layer With Golang

sqlair SQLite Query Layer Creates an abstract over the go sql package to provide

Feb 18, 2022
REST based Redis client built on top of Upstash REST API

An HTTP/REST based Redis client built on top of Upstash REST API.

Jul 31, 2022
a golang library for sql builder

Gendry gendry is a Go library that helps you operate database. Based on go-sql-driver/mysql, it provides a series of simple but useful tools to prepar

Dec 26, 2022
Fluent SQL generation for golang

Squirrel is "complete". Bug fixes will still be merged (slowly). Bug reports are welcome, but I will not necessarily respond to them. If another fork

Dec 29, 2022
convert sql to elasticsearch DSL in golang(go)

_____ _ _ ____ _____ ___ ____ ____ ___ _ | ____| | / \ / ___|_ _|_ _|/ ___|/ ___| / _ \ | | | _| | | / _ \ \___ \ |

Jan 7, 2023
GoTSQL : A Better Way to Organize SQL codebase using Templates in Golang

GoTSQL - A Better Way to Organize SQL codebase using Templates in Golang Installation through Go Get command $ go get github.com/migopsrepos/gotsql In

Aug 17, 2022