Code Monkey home page Code Monkey logo

tapestry's Introduction

Tapestry

Tapestry is a framework for writing (postgres)SQL queries and (pgTAP) tests using Jinja templates. It helps you write reusable SQL code and ensures that your pgTAP tests are testing the exact same SQL queries that are actually run by your application.

Tapestry is written in Rust but it can be used with applications written in any programming language. It's purely a command line tool that renders Jinja templates into SQL files. How to load the resulting SQL code into memory and use it at runtime is entirely up to the application.

This approach of loading SQL from files is not new. There are existing libraries such as yesql, hugsql (Clojure), aiosql (Python) etc. that provide excellent abstractions for it. In absence of such a lib for the language of your choice, it shouldn't take more than a few lines of code to implement a simple file loader. In Rust apps, I simply use the include_str! macro.

One limitation is that tapestry can only be used with PostgreSQL, because of the tight coupling with pgTAP.

You may find this tool useful if,

  1. you prefer direct SQL queries over ORMs or query builders to interact with RDBMS from application code

  2. you are not averse to the idea of having (reasonable amount of) business logic inside SQL queries

In fact, if you have had concerns about point 2 i.e. having business logic in SQL queries, perhaps tapestry addresses some of those concerns. Learn more about the rationale behind this tool.

Current status

Tapestry is a work in progress. But I am presently using it in my personal project so it has been tested for the basic use cases. A working example is also included in the repo which you may try out.

The first tag/version is yet to be created and released.

Installation

Currently, binaries for x86_64 arch for Linux and MacOS can be downloaded from the Github release page. (Binaries for arm/aarch64 platform and Windows OS are not available yet)

If you have the rust tool chain installed on your machine, you can build and install tapestry directly from github (without having to clone the repo).

cargo install --git https://github.com/naiquevin/tapestry.git

Additional dependencies

tapestry doesn't have any additional dependencies as such, but it can be optionally configured to depend on external SQL formatting tools. For more information, check the SQL formatting page in docs.

Read the docs

Detailed documentation about tapestry can be found here

Notable sections:

LICENSE

MIT (See LICENSE).

tapestry's People

Contributors

naiquevin avatar

Stargazers

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

Watchers

 avatar  avatar

tapestry's Issues

practical guidelines

Thanks for this nice library! What i would like to have is some guidelines on:

  • how would the typical REST CRUD look using tapestry?
  • would you recommend putting 'everything' (also non-dynamic queries) in this structure?

pg_prove installation

I'm using a postgres container image. AFAICT pg_prove needs to be installed on that container then right? So not on the host (vs pg_format which needs to be installed on the host/ render environment).

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.