Coder Social home page Coder Social logo

lkshminarayanan / omnigres Goto Github PK

View Code? Open in Web Editor NEW

This project forked from omnigres/omnigres

0.0 0.0 0.0 2.03 MB

Postgres as a Platform

Home Page: https://docs.omnigres.org/

License: Apache License 2.0

Shell 0.10% C++ 11.16% Python 0.31% C 80.95% Tcl 0.01% Nix 0.13% HTML 0.01% CMake 1.41% PLpgSQL 5.64% Dockerfile 0.29%

omnigres's Introduction

Omnigres

Documentation | Bounties


Discord Chat Documentation License

Omnigres makes Postgres a developer-first application platform. You can deploy a single database instance and it can host your entire application, scaling as needed.

  • Running application logic inside or next to the database instance
  • Deployment provisioning (Git, containers, etc.)
  • Database instance serves HTTP, WebSocket and other protocols
  • In-memory and volatile on-disk caching
  • Routine application building blocks (authentication, authorization, payments, etc.)
  • Database-modeled application logic via reactive queries
  • Automagic remote APIs and form handling
  • Live data updates

Blogs and Publications

๐Ÿƒ Quick start

The fastest way to try Omnigres out is by using its container image:

docker volume create omnigres
docker run --name omnigres --mount source=omnigres,target=/var/lib/postgresql/data \
           -p 127.0.0.1:5432:5432 -p 127.0.0.1:8080:8080 --rm ghcr.io/omnigres/omnigres:latest
# Now you can connect to it:
psql -h localhost -p 5432 -U omnigres omnigres # password is `omnigres`

Postgres parameters such as database, user or password can be overridden as per the "Environment Variables" section in postgres image instructions

You can access the HTTP server at localhost:8080

Building your own image

If you can't use the pre-built image (for example, you are running a fork or made changes), you can build the image yourself:

# Build the image
DOCKER_BUILDKIT=1 docker build . -t ghcr.io/omnigres/omnigres

๐Ÿ‘‹ "Hello, world"

Here we expect you are running the container image, which has omni_httpd and omni_web extensions provisioned by default.

Let's start with a traditional example. Here we will instruct the handler that is provisioned by omni_httpd by default to use the enclosed query to greet the world.

Below, we'll show examples in Python and plain SQL (or PL/pgSQL). Support for more languages is coming!

$ curl localhost:8080
Hello, world!
Python (Flask) implementation
from omni_python import pg
from flask import Flask
from omni_http.omni_httpd import flask

app = Flask('myapp')


@app.route('/')
def hello():
    return "Hello, world!"


handle = pg(flask.Adapter(app))

To connect the endpoint:

update omni_httpd.handlers
set
    query =
        $$select handle(request.*) from request$$;

NB: Please note that you will need to follow Python setup steps for the time being before our CLI tooling is ready.

Plain SQL

You can also achieve the same using plain SQL with very little setup.

update omni_httpd.handlers
set
    query =
        $$select omni_httpd.http_response('Hello, world!') from request$$;

Now, let's make it more personal and let it greet the requester by name.

$ curl "localhost:8080?name=John"
Hello, John!
Python (Flask) implementation
from flask import request  # we need to access `request`


@app.route('/')
def hello():
    return f"Hello, {request.args.get('name', 'world')}!"
Plain SQL
update omni_httpd.handlers
set
    query =
        $$select omni_httpd.http_response('Hello, ' || 
                   coalesce(omni_web.param_get(request.query_string, 'name'), 'world') || '!')
          from request$$;

This, of course, only barely scratches the surface, but it may give you a very high-level concept of how Omnigres web services can be built.

For a more complex example, that uses the underlying database and employs more real-world layout, check out this MOTD service example.

๐Ÿ—๏ธ Component Roadmap

Below is the current list of components being worked on, experimented with and discussed. This list will change (and grow) over time.

Name Status Description
omni_schema โœ… First release candidate Application schema management
omni_json โœ… First release candidate JSON toolkit
omni_xml โœ… First release candidate XML toolkit
omni_http โœ… First release candidate Common HTTP types library
omni_httpd and omni_web โœ… First release candidate Serving HTTP in Postgres and building services in SQL
omni_mimetypes โœ… First release candidate MIME types and file extensions
omni_httpc โœ… First release candidate HTTP client
omni_sql ๐Ÿšง Extremely limited API surface Programmatic SQL manipulation
omni_vfs โ˜‘๏ธ Initial prototype Virtual File System interface
omni_containers โ˜‘๏ธ Initial prototype Managing containers
omni_ext and Dynpgext interface โ˜‘๏ธ Getting ready to become first release candidate Advanced Postgres extension loader
omni_types โœ… First release candidate Advanced Postgres typing techniques (sum types, etc.)
omni_seq โœ… First release candidate Extended Postgres sequence tooling
omni_txn โœ… First release candidate Transaction management
omni_python โ˜‘๏ธ Initial prototype First-class Python Development Experience
omni_git ๐Ÿฅผ Early experiments (unpublished) Postgres Git client
omni_reactive ๐Ÿ—“๏ธ Haven't started yet Reactive queries

โŒจ๏ธ Hacking

Building & using extensions

To build and run Omnigres, you would need:

  • a recent C compiler
  • OpenSSL 3.1+
  • cmake >= 3.25.1
  • (optionally, to use omni_containers or run a full set of tests) a recent version of Docker
cmake -S . -B build
cmake --build build --parallel
make psql_<COMPONENT_NAME> # for example, `psql_omni_containers`

Troubleshooting

cmake not picking up Python version you want?

To use a specific Python build use the cmake flag Python3_EXECUTABLE:

cmake -S . -B build -DPython3_EXECUTABLE=/path/to/python
Build fails for whatever other reason?

Remove build and .pg directories for a clean rebuild:

rm -rf .pg build

Running tests

# in the build directory
CTEST_PARALLEL_LEVEL=$(nproc) make -j $(nproc) all test

Devenv.sh-based local development environment

Initial setup

Follow these guides:

  1. https://devenv.sh/getting-started/
  2. https://devenv.sh/automatic-shell-activation/
  3. Run direnv allow in omnigres repo

Day-to-day development

  1. cd into the repo. This brings in all dependencies.
  2. To bring up development stack (Postgres with all extensions, etc.), run: devenv up

Once the development environment is running, you can connect to it by issuing:

  • pg -> this connects to Postgres through a UNIX socket, for maximum performance. CLI args forwarded.
  • pgclear -> removes the PGDATA folder contents. You want to restart devenv up after this so Postgres can reinitialize as per devenv.nix.

omnigres's People

Contributors

yrashk avatar akshat-jain avatar rmodpur avatar idoqo avatar steve-chavez avatar abhishekmishragithub avatar inevolin avatar jamesits avatar joshinnis avatar thenonameguy avatar lkshminarayanan avatar svanderbleek avatar proger 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.