Git Product home page Git Product logo

pqt's Introduction

pqt GoDoc Build Status codecov.io

This package is a toolbox for postgres driven applications. It provides multiple tools to help to work with postgres efficiently. In comparison to other currently available libraries instead of pushing struct tags into anti pattern or parsing SQL, it allows to define schema programmatically.

It relies to a large degree on packages:

Features:

  • array support - golang postgres driver do not support arrays natively, pqt comes with help:
  • sql generation
  • go generation - it includes:
    • entity - struct that reflects single row within the database
    • criteria - object that can be passed to the Find method, it allows to create complex queries
    • patch - structure used by UpdateBy<primary-key> methods to modify existing entity
    • iterator - structure used by FindIter methods as a result, it wraps sql.Rows
    • constants:
      • table names
      • column names
      • constraints - library generates exact names of each constraint and corresponding constant that allow to easily handle query errors using ErrorConstraint helper function
    • repository - data access layer that expose API to manipulate entities:
      • Count - returns number of entities for given criteria
      • Find - returns collection of entities that match given criteria
      • FindIter - works like Find but returns iterator
      • Insert - saves given entity into the database
      • FindOneBy<primary-key> - retrieves single entity
      • UpdateBy<primary-key> - modifies single entity
      • DeleteBy<primary-key> - modifies single entity
    • func Scan<Entity>Rows(rows *sql.Rows) ([]*<entity>Entity, error) { helper function
  • schema definition - allow to programmatically define database schema, that includes:
    • schemas
    • tables
    • columns
    • constraints
    • relationships

Documentation

Example

Package itself do not provide any command line application that would generate output out of given input. Instead it encourage to write local generation application next to the proper package. Good example how such application could be structured can be found in examples.

By default example is trying to connect to local test database on default port. To run it simply call:

$ make gen // not necessary, since generated code is already part of the repo
$ make run

Contribution

Very welcome in general. Especially in fields like:

  • postgres types better support
  • support for functions
  • better control over if generated code is private or public

pqt's People

Contributors

piotrkowalczuk avatar

Watchers

 avatar  avatar

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.