Giter VIP home page Giter VIP logo

postgres-extension.rs's People

Contributors

rozgo avatar stereobooster avatar steveklabnik avatar thehydroimpulse 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

postgres-extension.rs's Issues

updated and uploaded

Hi,

I see that this has gone a while without update, and I put some work into getting this modernized on stable rust, and uploaded to crates.io.

If you are still interested, feel free to comment or contribute to my version of this project: https://github.com/jeff-davis/postgres-extension.rs

It's not in perfect shape yet, of course, still a lot of work to do.

Datum

Need to figure out a good story here. A datum is simply a pointer stored as a uint. Then casted to an appropriate type (in C). Text, for example, is allocated onto the heap using the custom pg_malloc allocator that allocates memory in contexts (regions). This enables it to easily clean up after a misbehaving extension, for example, in one whole swoop, instead of keeping track of a bunch of independent allocations that could never be freed.

Ideally, one could simply do:

Datum::new("foobar");
Datum::new(5i);
Datum::new(true);

Postgres has the concept of:

  • Pass by-value using a fixed length.
  • Pass by-reference using a fixed length.
  • Pass by-reference using a variable length.

Does not compile under rust 1.0.0-beta3

I just installed rust and could not get this project to build:

$ rustc --version
rustc 1.0.0-beta.3 (5241bf9c3 2015-04-25) (built 2015-04-25)

$ cargo build --verbose
Compiling postgres_extension v0.0.1 (file:///home/nathan/git/postgres-extension.rs)
Running rustc src/lib.rs --crate-name postgres_extension --crate-type dylib -g -C metadata=ccbbb938512147eb -C extra-filename=-ccbbb938512147eb --out-dir /home/nathan/git/postgres-extension.rs/target/debug --emit=dep-info,link -L dependency=/home/nathan/git/postgres-extension.rs/target/debug -L dependency=/home/nathan/git/postgres-extension.rs/target/debug/deps
src/lib.rs:7:20: 7:37 error: unresolved import core::marker::InvariantLifetime. There is no InvariantLifetime in core::marker
src/lib.rs:7 use core::marker::{InvariantLifetime, MarkerTrait};
^~~~~~~~~~~~~~~~~
src/lib.rs:7:39: 7:50 error: unresolved import core::marker::MarkerTrait. There is no MarkerTrait in core::marker
src/lib.rs:7 use core::marker::{InvariantLifetime, MarkerTrait};
^~~~~~~~~~~
error: aborting due to 2 previous errors
Could not compile postgres_extension.

Caused by:
Process didn't exit successfully: rustc src/lib.rs --crate-name postgres_extension --crate-type dylib -g -C metadata=ccbbb938512147eb -C extra-filename=-ccbbb938512147eb --out-dir /home/nathan/git/postgres-extension.rs/target/debug --emit=dep-info,link -L dependency=/home/nathan/git/postgres-extension.rs/target/debug -L dependency=/home/nathan/git/postgres-extension.rs/target/debug/deps (exit code: 101)

Doesn't build: no `intern` in `parse::token`

Trying to build using rustc 1.16.0-nightly (47c8d9fdc 2017-01-08), but it fails:

error[E0432]: unresolved import syntax::parse::token::intern
--> /Users/joel/src/postgres-extension.rs/macros/src/lib.rs:11:5
|
11 | use syntax::parse::token::intern;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no intern in parse::token

error[E0432]: unresolved import syntax::parse::token::InternedString
--> /Users/joel/src/postgres-extension.rs/macros/src/lib.rs:21:5
|
21 | use syntax::parse::token::InternedString;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no InternedString in parse::token

error: aborting due to 2 previous errors

error: Could not compile postgres_extension_macros.

Safe Interface

A few ideas I've had:

  • Remove the need to export extern functions using an attribute.
  • Super easy to work with data types like PgText, int16, etc... that can convert easily to a datum.
#[pg_export]
pub fn foobar(args: PgArgs) -> PgDatum {
    // ...
}

Support for JSON/JSONB

Since version 9.2, PostgreSQL has support for native JSON datatypes: json and jsonb (jsonb is a binary representation with more efficient access).

It would be pretty great to be able to manipulate those from Rust PgSQL extensions, though I guess it requires #2 to happen first.

My usecase would be an extension that validates a JSON value against a JSON Schema (itself represented as a JSON value).

PG_FUNCTION_ARGS

This is used for postgres-compatible functions. The macro is simply:

// src/include/fmgr.h 
#define PG_FUNCTION_ARGS FunctionCallInfo fcinfo

And you'd use it as:

Datum hello( PG_FUNCTION_ARGS );

We just need to define all the structures from C in Rust and we can define the function:

extern fn foobar(args: FunctionCallInfo) -> Datum {
    // ...
}

Build fails

Stable

cargo build --verbose
       Fresh natord v1.0.9 (https://github.com/lifthrasiir/rust-natord.git#93e5f0ac)
   Compiling postgres_extension_macros v0.0.1 (https://github.com/thehydroimpulse/postgres-extension.rs#5fdac67f)
     Running `rustc /.cargo/git/checkouts/postgres-extension.rs-6c32a33f6ee2475c/master/macros/src/lib.rs --crate-name postgres_extension_macros --crate-type dylib --crate-type rlib -C prefer-dynamic -g -C metadata=7dfee0560e913ba3 -C extra-filename=-7dfee0560e913ba3 --out-dir /my/pgxn-utils/natural_sort/target/debug/deps --emit=dep-info,link -L dependency=/my/pgxn-utils/natural_sort/target/debug/deps -L dependency=/my/pgxn-utils/natural_sort/target/debug/deps --cap-lints allow`
       Fresh libc v0.2.13
   Compiling postgres_extension v0.0.1 (https://github.com/thehydroimpulse/postgres-extension.rs#5fdac67f)
     Running `rustc /.cargo/git/checkouts/postgres-extension.rs-6c32a33f6ee2475c/master/src/lib.rs --crate-name postgres_extension --crate-type dylib -C prefer-dynamic -g -C metadata=142a984c1da92769 -C extra-filename=-142a984c1da92769 --out-dir /my/pgxn-utils/natural_sort/target/debug/deps --emit=dep-info,link -L dependency=/my/pgxn-utils/natural_sort/target/debug/deps -L dependency=/my/pgxn-utils/natural_sort/target/debug/deps --extern libc=/my/pgxn-utils/natural_sort/target/debug/deps/liblibc-a70a3ae81492eede.rlib --cap-lints allow`
/.cargo/git/checkouts/postgres-extension.rs-6c32a33f6ee2475c/master/src/lib.rs:1:1: 1:18 error: #[feature] may not be used on the stable release channel
/.cargo/git/checkouts/postgres-extension.rs-6c32a33f6ee2475c/master/src/lib.rs:1 #![feature(core)]
                                                                                              ^~~~~~~~~~~~~~~~~
error: aborting due to previous error
/.cargo/git/checkouts/postgres-extension.rs-6c32a33f6ee2475c/master/macros/src/lib.rs:1:1: 1:64 error: #[feature] may not be used on the stable release channel
/.cargo/git/checkouts/postgres-extension.rs-6c32a33f6ee2475c/master/macros/src/lib.rs:1 #![feature(plugin_registrar, quote, box_syntax, rustc_private)]
                                                                                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
Build failed, waiting for other jobs to finish...
error: Could not compile `postgres_extension_macros`.

Caused by:
  Process didn't exit successfully: `rustc /.cargo/git/checkouts/postgres-extension.rs-6c32a33f6ee2475c/master/macros/src/lib.rs --crate-name postgres_extension_macros --crate-type dylib --crate-type rlib -C prefer-dynamic -g -C metadata=7dfee0560e913ba3 -C extra-filename=-7dfee0560e913ba3 --out-dir /my/pgxn-utils/natural_sort/target/debug/deps --emit=dep-info,link -L dependency=/my/pgxn-utils/natural_sort/target/debug/deps -L dependency=/my/pgxn-utils/natural_sort/target/debug/deps --cap-lints allow` (exit code: 101)
cargo -V
cargo 0.10.0 (10ddd7d 2016-04-08)

Nightly

cargo build --verbose
       Fresh natord v1.0.9 (https://github.com/lifthrasiir/rust-natord.git#93e5f0ac)
       Fresh libc v0.2.13
   Compiling postgres_extension_macros v0.0.1 (https://github.com/thehydroimpulse/postgres-extension.rs#5fdac67f)
       Fresh postgres_extension v0.0.1 (https://github.com/thehydroimpulse/postgres-extension.rs#5fdac67f)
     Running `rustc /.cargo/git/checkouts/postgres-extension.rs-d576f8e53fa9bcec/master/macros/src/lib.rs --crate-name postgres_extension_macros --crate-type dylib --crate-type rlib -C prefer-dynamic -g -C metadata=521d4ffefa573a04 -C extra-filename=-521d4ffefa573a04 --out-dir /my/pgxn-utils/natural_sort/target/debug/deps --emit=dep-info,link -L dependency=/my/pgxn-utils/natural_sort/target/debug/deps -L dependency=/my/pgxn-utils/natural_sort/target/debug/deps --cap-lints allow`
/.cargo/git/checkouts/postgres-extension.rs-d576f8e53fa9bcec/master/macros/src/lib.rs:7:1: 7:26 error: can't find crate for `rustc_front` [E0463]
/.cargo/git/checkouts/postgres-extension.rs-d576f8e53fa9bcec/master/macros/src/lib.rs:7 extern crate rustc_front;
                                                                                                     ^~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
error: Could not compile `postgres_extension_macros`.

Caused by:
  Process didn't exit successfully: `rustc /.cargo/git/checkouts/postgres-extension.rs-d576f8e53fa9bcec/master/macros/src/lib.rs --crate-name postgres_extension_macros --crate-type dylib --crate-type rlib -C prefer-dynamic -g -C metadata=521d4ffefa573a04 -C extra-filename=-521d4ffefa573a04 --out-dir /my/pgxn-utils/natural_sort/target/debug/deps --emit=dep-info,link -L dependency=/my/pgxn-utils/natural_sort/target/debug/deps -L dependency=/my/pgxn-utils/natural_sort/target/debug/deps --cap-lints allow` (exit code: 101)
➜  natural_sort git:(master) rustc --version
rustc 1.10.0 (cfcb716cf 2016-07-03)
➜  natural_sort git:(master) cargo -V
cargo 0.11.0-nightly (259324c 2016-05-20)
source https://github.com/stereobooster/natural_sort-pgxn

Trying to reuse your code in guedes/pgxn-utils#40

cargo build fails in rust lang version 1.0.0

I tried to build on my Mac and got the following error.

  Compiling postgres_extension v0.0.1 (file:///Users/macpro/rust_projects/postgres-extension.rs)
src/lib.rs:42:13: 42:14 error: expected one of `(`, `+`, `::`, `;`, `<`, or `]`, found `,`
src/lib.rs:42     len: [i8, ..4],
                          ^
Could not compile `postgres_extension`.

Version of rust

rustc 1.0.0-nightly (91bdf23f5 2015-03-09) (built 2015-03-08)

Can you please help me with this

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.