Giter Club home page Giter Club logo

uform's Introduction

UForm

This is a novel implementation of the U-form abstract data type using PostgreSQL's JSONB Binary JSON field for attribute storage.

The inspiration for the U-fom goes back to Michael Dertouzos book which introduced the E-form. I did not invent the U-Form. I did work at MAYA Design where the U-Form was created.

My hope is to keep the idea alive in Open Source Software. While there are many similar models now such as Entity-Attribute-Value (EAV) or Datomic's 5-tuple, few of these existed when the U-Form was created.

See wikipedia for more information on the U-form.

The code provided here is based on PeeWee to establish the PostgreSQL connection, models, and attributes. This simplifies the code dramatically.

Installation and Configuration

  1. Clone the repository:

     https://github.com/davidthewatson/uform.git
    
  2. Change directories:

     cd uform
    
  3. Make a virtualenv:

     mkvirtualenv uform
    
  4. Install the python requirements:

     pip install -r requirements.txt
    
  5. Replace user variable with your postgres user in uform.py:

     db = PostgresqlExtDatabase(name, user='dwatson')
    
  6. Run the script:

     python example.py
    
  7. Examine the database:

     SELECT * FROM cats;
     "id","uuid","attrs"
     1,"012E201B-83BF-45E0-AD92-7EA9FC768464","{\"age\": 7, \"name\": \"Keiko\"}"
     2,"3590BD6B-F2BB-406A-8E93-80EE17AFF13A","{\"age\": 13, \"name\": \"Goose\"}"
     3,"85D3E0A7-7C8F-4B67-94E7-E0568A2D8ED3","{\"age\": 11, \"name\": \"Maxwell\"}"
    
  8. Examine the attributes of a particular cat:

     SELECT * FROM cats WHERE attrs->>'name' = 'Keiko';
     "id","uuid","attrs"
     1,"012E201B-83BF-45E0-AD92-7EA9FC768464","{\"age\": 7, \"name\": \"Keiko\"}"
    

Further Exploration

More advanced queries are left as an exercise for the reader. Suffice it so say that the full power of PostgreSQL is available and that query results on attributes are extremely fast provided that you create GIN indexes.

It's trivial to create REST interfaces for these models using PostgREST. PostgREST even enables querying the JSONB attributes through HTTP query parameters.

David Watson

uform's People

Contributors

davidthewatson avatar

Watchers

 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.