Coder Social home page Coder Social logo

sqlreflect's Introduction

SQL Reflect

THIS IS HIGHLY EXPERIMENTAL AND UNDER ACTIVE DEVELOPMENT

This library provides access to the structure of a SQL database, allowing developers to "reflect" on the database itself. Why would you need to do this?

  • Find out all of the tables available in a database
  • For a table, find out what columns it has
  • Find out about the relationships between tables
    • Discover foreign keys, and automatically relate tables
    • Discover primary keys

How It Works

This uses the information_schema database defined in the SQL standard. The library is developed against PostgreSQL, but it should work on any database that provides an approximately compliant implementation.

The information_schema tables (or views) provide information about the structure of a database, and are designed to enable this sort of reflection.

As the name of the library suggests, the code is designed to feel roughly similar to Go's own reflection package. However, there is not a one-to-one mapping between a concept like a table or column and Go's concepts like type and value.

Under the hood, it uses squirrel and structable 4.

Tested on:

  • Postgres 9.4, 9.6

Terminology

For the most part, this library follows the terminology of the SQL standard (e.g. catalog usually means database). Because I am most familiar with PostgreSQL, it is likely that some Postgres terminology slipped in here too.

Most of my understanding of the information schema comes from the PostgreSQL documentation.

TODO

  • Enable querying CHECK constraints to actually return the constraint. (See information_schame.check_constraints)

sqlreflect's People

Contributors

technosophos avatar

Watchers

James Cloos 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.