Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL Version 3 #65

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open

SQL Version 3 #65

wants to merge 23 commits into from

Conversation

biscuitWizard
Copy link
Contributor

This patch adds:

  • PostgreSQL support
  • SQLite support
  • Thread-safe forked queries
  • Prepared statements
  • Connection pooling and management builtins

The method signatures of the new built ins are:

sql_open(STR sql_url[, INT options]) => INT connection handle id.

This uses database://[user:password@][host][:port]/database[?name=value][&name=value]... format as described on https://www.tildeslash.com/libzdb/#api

Requests to open the same URL will result in it returning the existing handle_id for that URL, instead of creating a new connection pool.

Will return a string if an error has occurred.

Is capable of throwing E_INVARGs if invalid input is provided, or a general error occurs.

sql_close(INT handle_id) => INT true/false success.

Closes a connection at handle_id. If unable to for some reason, will return a string with the error.

sql_connections() => MAP of connection handles and urls

Returns a map of handle_id -> STR URL of active pools.

sql_query(INT handle_id, STR query[, LIST parameters]) => LIST of results

Queries handle_id (connection_pool) on another thread with query. ? marks are replaced by elements in the list of parameters in order that they are defined.

Results are a list of rows, with each row itself also being a list. {{row1_col1_value, row1_col2_value}, {row2_col1_value, row2_col2_value}, ...}

Will return a string if there is a SQL error. Is capable of throwing E_INVARGs if the parameters are invalid type. Only has support for primitive types (integer, string, floats).

Results will always be strings, regardless of what the database has the datatype defined as.

sql_info(INT handle_id) => MAP of settings

This is exactly like sqlite_info, just also returning the size of the connection pools.

The big difference between this and version 2 is that I rewrote it entirely to remove libzdb as a requirement, figuring I could do better. And I believe I did better, and removed one whole requirement. I've also written and added a lot of documentation, and removed sqlite formally which makes this a ....

BREAKING CHANGE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant