Coder Social home page Coder Social logo

xataio / pgzx Goto Github PK

View Code? Open in Web Editor NEW
343.0 5.0 6.0 6.94 MB

Create PostgreSQL extensions using Zig.

Home Page: https://xata.io

License: Apache License 2.0

Zig 85.58% C 0.76% Nix 5.86% Shell 7.30% Dockerfile 0.49%
extens extensions pgrx postgres postgresql zig ziglang

pgzx's People

Contributors

angaz avatar miukimiu avatar tsg avatar urso avatar xzilla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pgzx's Issues

Return NULL and log error instead of crashing PostgreSQL upon error?

Thanks for great work and a nice demo on YouTube.

In the demo, you showed how passing an empty string when expecting one char, resulted in an error that crashed PostgreSQL, albeit with a nice user-friendly error message from Zig, which is of course much better than the segfault C would cause.

However, crashing a production PostgreSQL database just because there is a bug in a Zig extension database function, might not always be desirable.

If possible, it would be nice with a setting that allows logging the error and just returning NULL instead of crashing.

Build system: Separate build from install

When using zig build it automatically defaults to zig build install. Out of the box one has an install and uninstall target.

When running zig build install our builds do compile the extension and copy all artifacts into the prefix path, which defaults to zig-out. The zig toolchain "jails" the install path so to say.

If you want to install the extension on your host postgres installation you might need to run the command via sudo. Unfortunately if the artifacts do not exist yet sudo would also affect the compilation (and ownership of the build artifacts).
The current workaround is to install the extension twice via:

$ zig build
$ sudo zig build -p $PG_HOME

The first call will install the extension into zig-out and the second call will install the extension on the host.

Internally we use $PG_HOME to determine the location of pg_config. If set correctly in step 1 nothing would be rebuild.

Using $PG_HOME on the command line feels redundant and might be confusing to our users.

As a first step I would like to update our build support to separate compilation from install. We already introduce custom steps in our build scripts like zig build pg_regress and zig build unit for testing. I would like to introduce another build step named compile that will only compile the artifacts, but not install them yet. CLI usage will become:

$ zig build compile
$ sudo zig build [install] -p $PG_HOME

Discussion on Discuss also proposed to introduce a deploy step. That would work similar to zig build install but would 'escape' the jail by copying the artifacts directly to the folders given by pg_config. CLI usage would become:

$ zig build compile
$ sudo zig build deploy

Note: When using zig build install we already used pg_config --<dir name> to determine the target folders. But encourage by how the zig build system installs files we use the configured install-prefix path instead of the absolute paths. In order to implement support for deploy we would either need to implement our own file/directory copy steps to have better control over the placement or take the easy route and have the deploy step recursively call zig build install -p $(dirname $(pg_config --bindir)).

Documentation

The readme is getting quite big and it is becoming difficult for users to find the right information or we didn't yet document things properly. To improve the DX and especially getting started experience I would like to split the readme out into a proper documentation.

TODO: sections/structure?

Build: Support to assemble SQL files

For some projects the accompanying SQL file can become quite large. I'd love to have support to split the SQL file for development purposes and combine them at build time.

Due to SQL files being statements being executed one after another users must be able to correctly configure the order of those files.

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.