lide.sql

[lide.sql] ^0.2

SQL Databases support for Lide framework.

Allow us to:

  • lide.sql library allows us to execute queries in sql databases from lua.
  • Get data from sql databases from lua.
  • Connect trought sqlite3 and firebird.

installation

To install this library I recommend using the command line of lide, using lide install.

$ lide install lide.sql

dependencies

The following dependencies are necessary to be able to run the library:


Database:new

Create new Database object and connect using given sql driver.

You can use “firebird” or “sqlite3” as sql database driver.

sqldb = sql.database:new ( 'sqlite3', 'test.db' );

SQLite3:

Database Database:new ( “firebird”, string sDatabase )

Firebird:

Database Database:new ( “sqlite3”, string sDatabase, string username, string password )

Database:exec

Executes the given SQL statement.
sqldb:exec 'select * from sqlite_master'
table Database:exec ( string QueryStatement )

Database:create_table

SQLite CREATE TABLE statement is used to create a new table in any of the given database. Creating a basic table involves naming the table and defining its columns and each column’s data type.
sqldb:create_table { lua_packages = {
    package_checksum = "Text",
    package_date = "Text",
    package_description = "Text",
    package_name = "Text",
    package_prefix = "Text",
    package_url = "Text",
    package_version = "Text",
    package_compat = "Text"
} };
nil Database:create_table { table_name = { col1name = string col1value, col2name = string col2value } }

Database:insert

Add new rows of data into a table in the database.
sqldb:insert { into = 'lua_packages',
    package_name = 'mypackage',
    package_description = 'Nuevo paquete',
    package_date = '2018-10-07',
    package_version = '1.0.0',
};
nil Database:insert { string into, col1name = string col1value, col2name = string col2value }

Database:update

Used to modify the existing records in a table. You must use WHERE clause with UPDATE query to update selected rows to prevent all the rows would be updated.
sqldb:update { 'lua_packages',
    where = "package_name like 'mypackage'",
    set = { package_description = 'Es una nueva version mucho mejor que las anteriores.' }
}
nil Database:update { string package_name, where = string WhereConditional, set = { col1name = col1value } }

Database:select

Fetch the data from a SQL database table which returns data in the form of a result table. These result tables are also called result sets.
sqll:select { from = 'lua_packages', 'package_name' }
nil Database:select { from = string table_name , string col1name, string col2value, … }