Coder Social home page Coder Social logo

sql-proxy-rs's Introduction

sql-proxy-rs

Programmable Postgres/MariaDB Proxy for Rust

Running Examples

Setting up

You'll need an instance of either Postgres or MariaDB running. If you have Docker Compose installed, this will bring up a PostgresSQL server, MariaDB server, and a container for compiling Rust.

$ docker-compose up

To attach an interactive shell into the Rust development container that was launched from Docker compose. You can attach as many shells as you'd like to run different things in the same container

$ make shell

Running tests

Lint

From the interactive shell above, run

$ bash scripts/check.sh

The script will run rustfmt, which automatically rewrites files to match the formatting rules. The script also runs clippy, which will only output errors that need to be addressed in order to pass CI

Integration tests

We currently have integration tests that test an end-to-end passthrough proxy. Run the following in the interactive shell (described above)

$ cargo test

Passthrough proxy

This example just silently forwards packets back and forth

$ RUST_LOG=info cargo run --example passthrough -- BIND_ADDR DB_ADDR [mariadb/postgres]
# For example:
$ RUST_LOG=info cargo run --example passthrough -- 0.0.0.0:3306 mariadb-server:3306 mariadb
$ RUST_LOG=info cargo run --example passthrough -- 0.0.0.0:5432 postgres-server:5432 postgres

Counter proxy

This example is the same as passthrough proxy, except it also logs any queries counts the types of queries going through (e.g. select, insert, create, etc.)

$ RUST_LOG=info cargo run --example counter -- BIND_ADDR DB_ADDR [mariadb/postgres]
# For example:
$ RUST_LOG=info cargo run --example counter -- 0.0.0.0:3306 mariadb-server:3306 mariadb
$ RUST_LOG=info cargo run --example counter -- 0.0.0.0:5432 postgres-server:5432 postgres

Running a SQL client

Assuming you used the previous setup scripts to run a proxy, you can use the following script to connect to your proxy and interactively issue SQL commands

$ make mysql    # client to a MariaDB proxy
OR 
$ make psql     # client to a Postgres proxy

sql-proxy-rs's People

Contributors

ryscheng avatar typeboi avatar nhynes avatar armaniferrante 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.