Giter Club home page Giter Club logo

rules_sqlc's Introduction

sqlc rules for Bazel

This repository contains rules for Bazel that allow you to compile your SQL files into a Go package that can be used for type-safe database code.

Table of Contents

  1. Setup
  2. Usage
  3. Documentation

Setup

The first thing you need to do is load the rules in your WORKSPACE file to make them available in your Bazel repository.

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "com_plezentek_rules_sqlc",
    sha256 = "ac0c69ad3f3f49a2f5c068a7ac946a52ce0d8389927f279eff2dca00f2631df1",
    urls = [
        "https://github.com/plezentek/rules_sqlc/releases/download/v0.9.1/rules_sqlc-v0.9.1.tar.gz"
    ],
)

load("@com_plezentek_rules_sqlc//sqlc:deps.bzl", "sqlc_register_toolchains", "sqlc_rules_dependencies")

sqlc_rules_dependencies()

sqlc_register_toolchains()

Pass in a version to sqlc_register_toolchains if your code depends on an older version of the compiler:

sqlc_register_toolchains(version="1.5.0")

If you'd like to use the development version of these rules, you can fetch them with git_repository by setting the commit parameter to a recent commit hash.

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
    name = "com_plezentek_rules_sqlc",
    commit = "<RECENT_COMMIT>",
    remote = "https://github.com/plezentek/rules_sqlc",
)

load("@com_plezentek_rules_sqlc//sqlc:deps.bzl", "sqlc_register_toolchains", "sqlc_rules_dependencies")

sqlc_rules_dependencies()

sqlc_register_toolchains()

Usage

In order to generate a Go package called database, use the following sql_package rule.

load("@com_plezentek_rules_sqlc//sqlc:def.bzl", "sqlc_package")

sqlc_package(
    name = "product_database",
    package = "database",
    queries = ["query.sql"],
    schema = ["schema.sql"],
)

You can combine this with rules_go in order to compile a Go library. Notice how the package and the importpath coincide.

load("@com_plezentek_rules_sqlc//sqlc:def.bzl", "sqlc_package")
load("@io_bazel_rules_go//go:def.bzl", "go_library")

sqlc_package(
    name = "product_database",
    package = "database",
    queries = ["query.sql"],
    schema = ["schema.sql"],
)

go_library(
    name = "product_library",
    srcs = [":product_database"],
    importpath = "example.com/owner/repo/database",
)

Documentation

Full details on the use of the sqlc_package rule can be found in the rules documentation.

The SQLCRelease bazel provider (for writers of further bazel rules) can be found in the provider documentation.

rules_sqlc's People

Contributors

dmayle avatar douglas-plezentek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rules_sqlc's Issues

Provide documentation

Thanks for contributing these rules.

I think it would make sense to discuss feedback from other vendors for SQLC.

What issues need solving?

Create contributor guidelines

Add documentation in CONTRIBUTING/README.md that explains pre-requisites for contributions:

  • Sign the license agreement (not yet automated)

Add another file in the same directory that specifies how to contribute

A bug report

  • Requested details
  • Example bug reports

A new feature

  • New features require a new test in /tests
  • Run bazel test //test/... before submitting to make sure all tests pass

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.