spanner-logo

Google Spanner SpanSQL Query Builder

License Build Status Go Reference

High level lightweight spansql query builder. This is not an officially supported Google product.

Install

go get -u github.com/mindful-hq/spansql-query-builder

Example

var sql, params = query_builder.New().
    Select([]spansql.Expr{
        spansql.ID("Todos.Id"),
        spansql.ID("Places.Name"),
    }).
    Table(spansql.SelectFromTable{
        Table: "Todos",
    }).
    Join(query_builder.SelectFromJoin{
        Type: spansql.InnerJoin,
        LHS:  spansql.SelectFromTable{Table: "Places"},
        On:   spansql.ComparisonOp{Op: spansql.Eq, LHS: spansql.PathExp{"Todos", "Id"}, RHS: spansql.PathExp{"Places.TodoId"}},
    }).
    Where(spansql.ComparisonOp{Op: spansql.Eq, LHS: spansql.ID("Id"), RHS: spansql.IntegerLiteral(1)}).
    Where(spansql.ComparisonOp{Op: spansql.Like, LHS: spansql.ID("Name"), RHS: spansql.StringLiteral("%test%")}).
    SQL()
SELECT Todos.Id, Places.Name FROM Todos INNER JOIN Places ON Todos.Id = Places.TodoId WHERE Id = 1 AND Name LIKE "%test%"

Play with it: Go Playground

GitHub

View Github