Giter Club home page Giter Club logo

leya's Introduction

Leya 3.0.0

Formerly "Improv3d API"

Gitter chat

About

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.

Installation

  • Open config.php, fill in your server data and adjust permissions.
  • Upload the leya.php and config.php files.

Api Response

data

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.

error

When the __error value is empty or 0, no error occurred, while executing the function.

affectedRows

The amount of rows, that got affected by the function.

example

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
    }
  }
}

Methods

Database

Basic

Rows

  • createRow(table, row)
  • deleteRow(table, row)
  • listRows(table)
  • countRows(table)
  • rowExist(table, row)

Columns

  • listColumns(table)
  • addColumn(table, column)
  • deleteColumn(table, column)
  • renameColumn(table, column, value)
  • setColumn(table, column, type, length)

Table

  • createTable(table, columns)
  • deleteTable(table)
  • tableExist(table)
  • checkTable(table)
  • exec(query)

File

  • fileWrite(file, content, mode)
  • fileRead(file)
  • fileDelete(file)
  • fileRename(file, name)
  • fileExists(file)
  • fileCopy(file, destination)
  • fileSize(file, unit)

Misc

  • hash(content, algorithm)
  • mail(reciever, message, subject)
  • generateKey()
  • join(array, seperator)

Properties

  • leya.server
  • leya.key
  • leya.debug

Examples

#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

Security

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.