PGX: Write Postgres extensions in Rust instead oc C

栏目: IT技术 · 发布时间: 5年前

内容简介:First you'll want to install the

PGX: Write Postgres extensions in Rust instead oc C

pgx

Build Postgres Extensions with Rust!

pgx is a framework for developing PostgreSQL extensions in Rust and wants to make that process as idiomatic and safe as possible. Currently, pgx supports Postgres v10, v11, and v12.

Key Features

  • A cargo sub-command ( pgx ) for creating, compiling/installing, and testing extensions
  • Postgres Datum <-->Rust type conversion via pgx::IntoDatum and pgx::FromDatum
  • Safe handling of NULL Datums -- Datums are simply Option<T>
  • Translation of Rust panic!() s into Postgres ERROR s, which abort the current transaction instead of the Postgres cluster
  • #[derive(PostgresType)] macro for automatically generating Postgres types based on Rust structs
  • #[derive(PostgresEnum)] macro for automatically generating Postgres enums based on Rust enums
  • extension_sql!() macro for providing custom extension schema DDL
  • #[pg_extern] proc-macro for automatically creating UDFs
  • Automatic extension schema generation
  • Transparent support for generating Set Returning Functions (SRFs) by returning a std::iter::Iterator<Item = T>
  • #[pg_test] proc-macro for unit tests that run in-proccess in Postgres
  • PgMemoryContexts wrapper around Postgres' "MemoryContext" system
  • Executor/planner/transaction/subtransaction hook support
  • #[pg_guard] proc-macro for guarding extern "C" Rust functions that need to be passed into Postgres
  • Basic SPI support
  • Direct unsafe access to large parts of Postgres internals via the pgx::pg_sys module
  • Separation of Postgres symbols (types, functions, etc) by what's common across all supported versions, and then version-specific modules
  • lots more!

Getting Started

First you'll want to install the pgx cargo sub-command from crates.io. You'll use it almost exclusively during your development and testing workflow.

$ cargo install cargo-pgx

It has a number of sub-commands. For example, to create a new extension project, simply run:

$ cargo pgx new my_extension

Then cd my_extension and run:

$ cargo pgx install

The first time, this will take awhile. Behind the scenes, pgx is downloading, configuring, compiling and installing (within target/ ) Postgres v10, v11, and v12. All of this happens in the target/ directory and the artifacts will remain until a cargo clean . This is necessary in order to generate the proper Rust bindings for Postgres internals.

Note that cargo pgx install will compile your extension and then install it to your locally installed Postgres instance as identified by pg_config , so make sure that pg_config is in your $PATH .

From here, you can create a Postgres database and create your extension in it:

$ createdb test
$ psql test
> CREATE EXTENSION my_extension;
> SELECT hello_my_extension();

Digging Deeper

Contributing

We are most definitely open to contributions of any kind. Bug Reports, Feature Requests, Documentation, and even sponsorships .

Providing wrappers for Postgres' internals is not a straightforward task, and completely wrapping it is going to take quite a bit of time. pgx is generally ready for use now, and it will continue to be developed as time goes on. Your feedback about what you'd like to be able to do with pgx is greatly appreciated.

License

Copyright 2020 ZomboDB, LLC <zombodb@gmail.com>. All rights reserved. 
Use of this source code is governed by the MIT license that can be found in the LICENSE file.

以上所述就是小编给大家介绍的《PGX: Write Postgres extensions in Rust instead oc C》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

未来是湿的

未来是湿的

[美] 克莱·舍基 / 胡泳、沈满琳 / 中国人民大学出版社 / 2009-5 / 39.80

一位妇女丢掉了手机,但征召了一群志愿者将其从盗窃者手中夺回。一个旅客在乘坐飞机时领受恶劣服务,她通过自己的博客发动了一场全民运动。在伦敦地铁爆炸案和印度洋海啸中,公民们用可拍照手机提供了比摄影记者更完备的记录。世界上最大的百科全书是由管理甚少的参与者们撰写的…… 不论在何处,你都能看见人们走到一起彼此分享,共同工作,或是发起某种公共行动。一部集众人之力的百科全书、一个丢失手机的传奇,这些事情......一起来看看 《未来是湿的》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具