Skip to main content

Stand alone version of Record_MySQL from Rest-OC to facilitate updating code to newer librairies. Has since been updated far beyond Rest-OC.

Project description

rest_mysql

pypi version MIT License

Stand alone version of Record_MySQL from Rest-OC to facilitate updating code to newer librairies. Since forking off of Rest-OC numerous improvements and bug fixes have been done.

See Releases for changes from release to release.

Full Documentation

Install

Requires

rest_mysql requires python 3.10 or higher

Install via pip

foo@bar:~$ pip install rest_mysql

Updating from Rest-OC

Instead of pulling Record_MySQL from RestOC as we did in the past, change any references to rest_mysql

Old:

from RestOC import Record_MySQL
from RestOC.Record_MySQL import db_create, Record
from RestOC.Record_Base import register_type

New:

from rest_mysql import Record_MySQL
from rest_mysql.Record_MySQL import db_create, Record
from rest_mysql.Record_Base import register_type

Binary UUID and UUIDv4

If you're using uuid or uuid4 define types and you run into problems with UUID_TO_BIN and BIN_TO_UUID, you will need to install the functions, or an alias

Note

Before continuing, I would suggest switching to tuuid or tuuid4 as these represent trimmed UUIDs, which can be turned to binary and back without the use of UUID_TO_BIN or BIN_TO_UUID. If you absolutely must have full UUIDs, then choose from the below server types to continue fixing the issue.

MySQL

MySQL provides the functions, but in order for rest_mysql to be supportive of all system, it defaults to assuming the function is part of the database schema. To solve this, make aliases to the global functons

from rest_mysql.Record_MySQL import Commands

db = 'your_db_name'
Commands.execute('primary', [

	"CREATE FUNCTION `%s`.`BIN_TO_UUID`(b BINARY(16))\n" \
	"RETURNS CHAR(36) DETERMINISTIC\n" \
	"BEGIN\n" \
	"	return BIN_TO_UUID(b);\n" \
	"END" % db,

	"CREATE FUNCTION `%s`.`UUID_TO_BIN`(uuid CHAR(36))\n" \
	"RETURNS BINARY(16) DETERMINISTIC\n" \
	"BEGIN\n" \
	"	RETURN UUID_TO_BIN(uuid);\n" \
	"END" % db
])

MariaDB

MariaDB does not provide UUID_TO_BIN and BIN_TO_UUID as it has its own uuid type which doesn't support the standard sql way of storing binary UUIDs. You can add the functions to the database schema like so

from rest_mysql.Record_MySQL import Commands

db = 'your_db_name'
Commands.execute('primary', [

	"CREATE FUNCTION `%s`.`BIN_TO_UUID`(b BINARY(16))\n" \
	"RETURNS CHAR(36) DETERMINISTIC\n" \
	"BEGIN\n" \
	"	DECLARE hexStr CHAR(32);\n" \
	"	SET hexStr = HEX(b);\n" \
	"	RETURN LOWER(CONCAT(" \
			"SUBSTR(hexStr, 1, 8), '-', " \
			"SUBSTR(hexStr, 9, 4), '-', " \
			"SUBSTR(hexStr, 13, 4), '-', " \
			"SUBSTR(hexStr, 17, 4), '-', " \
			"SUBSTR(hexStr, 21)" \
		"));\n" \
	"END" % db,

	"CREATE FUNCTION `%s`.`UUID_TO_BIN`(uuid CHAR(36))\n" \
	"RETURNS BINARY(16) DETERMINISTIC\n" \
	"BEGIN\n" \
		"RETURN UNHEX(REPLACE(uuid, '-', ''));\n" \
	"END" % db
])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rest_mysql-1.2.3.tar.gz (31.3 kB view details)

Uploaded Source

File details

Details for the file rest_mysql-1.2.3.tar.gz.

File metadata

  • Download URL: rest_mysql-1.2.3.tar.gz
  • Upload date:
  • Size: 31.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.31.0 rfc3986/1.5.0 tqdm/4.65.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for rest_mysql-1.2.3.tar.gz
Algorithm Hash digest
SHA256 a612109bc2dba2eff763a0b430e18bb9a83c6a8abde2131ef709fec8eb2ea8f7
MD5 1b833951e5ce0c4c08b88229345eae9b
BLAKE2b-256 37b70c5883591be7f0c532f69f9dc45b788558ee963648b4f8656a5f3287e606

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page