GithubHelp home page GithubHelp logo

quenkar / pgwire Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sunng87/pgwire

0.0 0.0 0.0 588 KB

PostgreSQL wire protocol implemented as a rust library.

License: Apache License 2.0

Shell 0.26% JavaScript 0.41% Python 0.47% Clojure 0.30% Rust 98.56%

pgwire's Introduction

pgwire

CI Docs

This library implements PostgreSQL Wire Protocol, and provide essential APIs to write PostgreSQL comptible servers and clients.

This library is a work in progress and in its relatively early stage. There is no guarantee for API stability. I'm constantly introducing break changes during this period. And also sorry for lack of API docs, examples may get you familiar with its usage.

Status

  • Message format
    • Frontend-Backend protocol messages
    • Logical replication streaming protocol message
  • Backend TCP/TLS server on Tokio
  • Frontend-Backend interaction over TCP
    • SSL Request and Response
    • Startup
      • No authentication
      • Clear-text password authentication
      • Md5 Password authentication
      • SASL SCRAM authentication
        • SCRAM-SHA-256
        • SCRAM-SHA-256-PLUS
    • Simple Query and Response
    • Extended Query and Response
      • Parse
      • Bind
      • Execute
      • Describe
      • Sync
    • Termination
    • Cancel
    • Error and Notice
    • Copy
  • Logical replication over TCP
  • APIs
    • Startup APIs
      • AuthSource API, fetching and hashing passwords
      • Server parameters API, ready but not very good
    • Simple Query API
    • Extended Query API
      • QueryParser API, for transforming prepared statement
      • PortalStore API, for caching statements and portals
    • ResultSet builder/encoder API
    • Query Cancellation API
    • Error and Notice API
    • Copy API
      • Copy-in
      • Copy-out
      • Copy-both
    • Logical replication server API

About Postgres Wire Protocol

Postgres Wire Protocol is a relatively general-purpose Layer-7 protocol. There are 3 parts of the protocol:

  • Startup: client-server handshake and authentication.
  • Simple Query: The legacy query protocol of postgresql. Query are provided as string, and server is allowed to stream data in response.
  • Extended Query: A new sub-protocol for query which has ability to cache the query on server-side and reuse it with new parameters. The response part is identical to Simple Query.

Also note that Postgres Wire Protocol has no semantics about SQL, so literally you can use any query language, data formats or even natural language to interact with the backend.

The response are always encoded as data row format. And there is a field description as header of the data to describe its name, type and format.

Usage

Server/Backend

To use pgwire in your server application, you will need to implement two key components: startup processor and query processor. For query processing, there are two kinds of queries: simple and extended. By adding SimpleQueryHandler to your application, you will get psql command-line tool compatibility. And for more language drivers and additional prepared statement, binary encoding support, ExtendedQueryHandler is required.

Examples are provided to demo the very basic usage of pgwire on server side:

  • examples/sqlite.rs: uses an in-memory sqlite database at its core and serves it with postgresql protocol. This is a full example with both simple and extended query implementation.
  • examples/gluesql.rs: uses an in-memory gluesql at its core and serves it with postgresql protocol.
  • examples/server.rs: demos a server that always returns fixed results.
  • examples/secure_server.rs: demos a server with ssl support and always returns fixed results.
  • examples/scram.rs: demos how to configure more secure authentication mechanism: SCRAM
  • examples/datafusion.rs: demos a postgres compatible server backed by datafusion query engine. This example allows you to LOAD csv files as datafusion table and run SELECT queries on them.

Client/Frontend

I think in most case you do not need pgwire to build a postgresql client, existing postgresql client like rust-postgres should fit your scenarios. Please rise an issue if there is a scenario.

Projects using pgwire

License

This library is released under MIT/Apache dual license.

pgwire's People

Contributors

dependabot[bot] avatar penberg avatar sunng87 avatar zyy17 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.