This repository contains the source code for a MySQL loadable function library (previously called UDF - User Defined Functions), which provides an additonal SQL astrononmy function to get astro sun and moon information for a given geographical location and time.
The calculations are based on an adaptation of the C++ Astronomy class from ESP32-Astronomie.
If you like lib_mysqludf_astro give it a star or fork it:
From the base directory run:
make clean
make
sudo make install
This will build and install the library file.
To create a country-specific version, call make command with the parameter LANG=-DLANG_xx, where xx is the country code: DE=German, ES=Spanish, FR=French, IT=Italian, NL=Netherlands, EN=English (default).
Example: Create and install a Dutch binary use
make clean
make LANG=-DLANG_NL
sudo make install
Finally we activate the loadable function in MySQL Server (replace username
by a local MySQL user which has the permission to create functions, e. g. root)
mysql -u username -p < install.sql
To uninstall first deactive the loadable function within your MySQL server using the SQL queries:
DROP FUNCTION IF EXISTS astro_info;
DROP FUNCTION IF EXISTS astro;
then uninstall the library using command line:
sudo make uninstall
Returns astro info for given date, geolocation and timezone as JSON string.
A given valid date in 'YYYY-MM-DD hh:mm:ss' format. Invalid dates results in a NULL value.
North–south position of a point in degrees format
East-West position of a point in degrees format
Time zone offset from UTC in hours
The function returns the astro info as JSON string with the following keys:
JSON Key | Description | Format/Unit |
---|---|---|
$.Time | Date for the given result | 'YYYY-MM-DDThh:mm:ss' |
$.Zone | Time zone offset from UTC in hours | hour |
$.Latitude | Geographic latitude | degrees |
$.Longitude | Geographic longitude | degrees |
$.deltaT | deltaT | decimal |
$.JulianDate | Julian Date | decimal |
$.GMST | Greenwich sidereal time | 'hh:mm:ss' |
$.LMST | Local sidereal time | 'hh:mm:ss' |
$ |