Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.
/ pgx_strings_demo Public archive

A simple string maniplulation PostgreSQL extension written in Rust using pgx, for learning purpose.

Notifications You must be signed in to change notification settings

kw7oe/pgx_strings_demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Warning

As pgx is being renamed to pgrx, this repository is outdated. Please head over to https://github.com/kw7oe/pgrx_string_demo for the updated version.

A example of PostgreSQL extensions using pgx

This project includes a simple PostgreSQL extension written in Rust, using the pgx crate. This extension contains the following string manipulations functions:

  • to_title: Convert a given string to title case.
  • emojify: Convert any emoji shortcode in a string to emoji.

This is extension is for demonstration and learning purposes and by no mean for using it in production.

If you would like to learn more about it you can refer to this post: Writing PostgreSQL extension in Rust With pgx

Getting Started

  1. Install and setup cargo-pgx. For more, refer to the Getting Started of pgx
cargo install cargo-pgx
cargo pgx init
  1. Clone this repository and change directory into it.
  2. Run it using cargo pgx run pg14. This will spin up a PostgreSQL.
  3. In your psql session, load the extension first:
pgx_strings=# create extension pgx_strings;
CREATE EXTENSION

pgx_strings=# \df
                             List of functions
 Schema |       Name        | Result data type | Argument data types | Type
--------+-------------------+------------------+---------------------+------
 public | emojify           | text             | string text         | func
 public | hello_pgx_strings | text             |                     | func
 public | to_title          | text             | string text         | func
(3 rows)
  1. Now with everything loaded you can run the following SQL:
pgx_strings=# select hello_pgx_strings();
 hello_pgx_strings
--------------------
 Hello, pgx_strings
(1 row)

pgx_strings=# select to_title('this is so cool');
    to_title
-----------------
 This Is So Cool
(1 row)

pgx_strings=# select emojify('I love pgx :100:');
   emojify
--------------
 I love pgx 💯
(1 row)

About

A simple string maniplulation PostgreSQL extension written in Rust using pgx, for learning purpose.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages