Skip to content

2rebi/mysql_udf_http_golang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mysql_udf_http_golang

MySQL or MariaDB UDF(User-Defined Functions) HTTP Client Plugin

Call RESTful API on query.

Setup

  • Clone Source
git clone https://github.com/RebirthLee/mysql_udf_http_golang.git udf cd udf
  • Auto Build
bash ./install.sh {username} {password}

{username} replace your MySQL or MariaDB Username.
{password} replace your MySQL or MariaDB Password(Optional).

  • Manual Build
bash ./build.sh

Build output is http.so, move file to plugin_dir path.
if you don't know plugin_dir path.
Command input this on MySQL, MariaDB connection.

SHOW VARIABLES LIKE 'plugin_dir'; 

Ex)

$ mysql -u root -p Enter password: 

And

MariaDB [(none)]> SHOW VARIABLES LIKE 'plugin_dir'; +---------------+-----------------------------------------------+ | Variable_name | Value | +---------------+-----------------------------------------------+ | plugin_dir | /usr/local/Cellar/mariadb/10.3.12/lib/plugin/ | +---------------+-----------------------------------------------+ 1 row in set (0.001 sec)

and http.so move to Value path.

mv ./http.so /usr/local/Cellar/mariadb/10.3.12/lib/plugin/

Finally, execute query

  • HTTP HELP
CREATE FUNCTION http_help RETURNS STRING SONAME 'http.so';
  • HTTP GET
CREATE FUNCTION http_get RETURNS STRING SONAME 'http.so';
  • HTTP POST
CREATE FUNCTION http_post RETURNS STRING SONAME 'http.so';

Usage

- Help

SELECT http_help();

- GET Method

  • Prototype
SELECT http_get(url, option...);
  • Simple Request
SELECT http_get('http://example.com');

Return

{ "Body": String(HTML) }
  • Output Option
    -O outputTypeDefine kind of result.

  • Kinds
    PROTO, STATUS or STATUS_CODE, HEADER, BODY(default), FULL
    -O PROTO|STATUS|HEADER|BODY same this -O FULL.

SELECT http_get('http://example.com', '-O FULL');

Return

{ "Proto": String(Http Version, HTTP/1.0, HTTP/1.1, HTTP/2.0), "Status": String(Status Code, 200 OK, 404 NOT FOUND), "Header": JSON(`{Key : Array, ...}`), "Body": String(HTML, Base64, Hexdecimal) }

writing... plz wait...

Add Soon

- POST Method

SELECT http_post();

License

THE BEER-WARE LICENSE (Revision 42)

About

MySQL(or MariaDB) UDF(User-Defined Functions) Http Client Plugin.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •