Formerly "Improv3d API"
Leya is an api that enables the work with MySQL databases in autohotkey, without exposing server credentials to the client. This is done by running the api on a php server, between the client and the database.
In addition to that, you get a powerful authentification & permission system.
You don´t need to write any SQL queries, leya gives you a collection of commands to access and alter the database, and builds the queries for you.
- Open
config.php
, fill in your server data and adjust permissions. - Upload the
leya.php
andconfig.php
files.
The api responds with an object containing your data and metadata. When requesting an array of rows, with methods like getWhere, the results are put into an array with the name of the database.
When the __error value is empty or 0, no error occurred, while executing the function.
The amount of rows, that got affected by the function.
Let's say you executed the get method and requested "username" and "role". Your response is going to look like this:
{
data {
username
role
}
error
affectedRows
}
#include leya.ahk
leya.server := "http://my-server.com/leya.php"
req := leya.get("users", "playerA", "first_name, last_name")
player := req.data
if req.error
msgbox % req.error
else
msgbox The fullname of playerA is %player.first_name% %player.last_name%.
#include leya.ahk
leya.server := "http://my-server.com/leya.php"
req := leya.getWhere("users", "*", "age", ">=", "18")
if req.error
msgbox % req.error
else {
msgbox Found %req.affectedRows% users over 18.
if req.users {
; loop over all users, over the age of 18
for index, user in req.data.users {
msgbox % user.first_name " " user.last_name
}
}
}
- get(table, row, column)
- getWhere(table, column, conditionColumn, operator, conditionValue)
- set(table, row, column, value)
- compare(table, row, column, value, caseInsensitive)
- createRow(table, row)
- deleteRow(table, row)
- listRows(table)
- countRows(table)
- rowExist(table, row)
- listColumns(table)
- addColumn(table, column)
- deleteColumn(table, column)
- renameColumn(table, column, value)
- setColumn(table, column, type, length)
- createTable(table, columns)
- deleteTable(table)
- tableExist(table)
- checkTable(table)
- exec(query)
- fileWrite(file, content, mode)
- fileRead(file)
- fileDelete(file)
- fileRename(file, name)
- fileExists(file)
- fileCopy(file, destination)
- fileSize(file, unit)
- hash(content, algorithm)
- mail(reciever, message, subject)
- generateKey()
- join(array, seperator)
- leya.server
- leya.key
- leya.debug
#include leya.ahk
leya.server := "http://my-server.com/leya.php"
player := leya.get("users", "playerA", "level")
msgbox PlayerA is on Level %player.level%
#include leya.ahk
leya.server := "http://my-server.com/leya.php"
; get an array with the names of users, where "level" is greater than 3
pros := leya.getWhere("users", "name", "level", ">", 3)
; turn the array into a comma seperated string
list := leya.join(pros, ", ")
msgbox %list% are over level 3.
#include leya.ahk
leya.server := "http://my-server.com/leya.php"
player := leya.get("users", "improv3d", "*")
msgbox % "Name: " player.name " Level: " player.level
If you share your application with others, they could figure out the url to your server and use the api against you. Depending on your configuration, they could read anything from the database, modify data or even delete all tables.
Don´t worry, the api has functions, to prevent this.
You should always use Authentication-Keys, so someone without a key, can´t access the api. When you´re working with multiple users, assign individual keys for every user, so you could easily block someone, or limit their permissions.
Only give users the permissions they need.
Don't hardcode keys in your application. Import them from a txt file or let users enter them.
FileRead, userkey, %A_ScriptDir%/apikey
leya.key := userkey