Giter Site home page Giter Site logo

jeromer / sqrible Goto Github PK

View Code? Open in Web Editor NEW
15.0 1.0 2.0 29 KB

Generates Go code that matches your Postgres tables

License: BSD 3-Clause "New" or "Revised" License

Makefile 8.09% Smarty 8.40% Go 83.52%
sqlx pgx golang postgresql code-generator

sqrible's Introduction

Problematic

Sqrible came out of the frustation of working with pgx and sqlx.

I had to buid a crappy bridge which led to nowhere and this did not solve the problem that for every request sqlxhas to use Golang's reflection to map query results to struct fields.

This did not sound right.

The other option is to map each field manually but that's tedious and error prone.

So the solution is to generate go code that would do everything automatically.

The advantages are:

  • I no longer need sqlx and thus limit reflection usage to pgx
  • With a set of template I can generate the code I need and update it easily with a few template changes

How does it work ?

Sqrible scans informations about a given table, reads what you configured for this table in a yaml config file and output the generated code you built with the provided template.

Building

make deps build

Usage

./bin/sqrible --help

Usage of ./bin/sqrible:
  -c string
        /path/to/config/file.yaml
  -d string
        template dir
  -t string
        table name

Examples

Have a look in the examples directory which contains one simple template which showcases informations sqrible has about a table. The advanced example showcases a more real life usage.

Demo

Other projects in this field

FAQ

Do you plan to support other DBMSes ?

No. I only need Postgres support and do not plan to provide any support for MySQL, Oracle ... Have at look at xo ;)

sqrible's People

Contributors

jeromer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

richp10 kainsk

sqrible's Issues

Advanced example

The example template in the advanced folder seems to be the same as the simple one.. I wonder if you could provide more examples of how the utility can be used... such as the template to produce the 'generated.go' shown in the video.

Your version seems to be much better than pgxdata at assigning the correct data types.. so I hope I can figure out more comprehensive templates!

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.