Skip to content

Commit

Permalink
Add example.lua and README.md file
Browse files Browse the repository at this point in the history
  • Loading branch information
ThymonA committed Dec 30, 2020
1 parent 886872c commit ec81100
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# FiveM MySQL - MySQL library for FiveM
[![N|CoreV](https://i.imgur.com/wA7DmUS.png)](https://github.com/ThymonA/fivem-mysql)
[![Issues](https://img.shields.io/github/issues/ThymonA/fivem-mysql.svg?style=for-the-badge)](https://github.com/ThymonA/fivem-mysql/issues)
[![License](https://img.shields.io/github/license/ThymonA/fivem-mysql.svg?style=for-the-badge)](https://github.com/ThymonA/fivem-mysql/blob/master/LICENSE)
[![Forks](https://img.shields.io/github/forks/ThymonA/fivem-mysql.svg?style=for-the-badge)](https://github.com/ThymonA/fivem-mysql)
[![Stars](https://img.shields.io/github/stars/ThymonA/fivem-mysql.svg?style=for-the-badge)](https://github.com/ThymonA/fivem-mysql)

This mysql-async Library for FiveM intends to provide function to connect to a MySQL in a Sync and Async way. This resource is inspired by [`fivem-mysql-async`](https://github.com/brouznouf/fivem-mysql-async) and written by [ThymonA](https://github.com/ThymonA/)

### **Example**
If you want to know how this resource works? check the [`example.lua`](https://github.com/ThymonA/fivem-mysql/blob/master/example.lua) file inside this resource.

### **Config the `server.cfg`**
**Config** | **Description** | **Default**
:----------|:----------------|:----------------
`mysql_connection_string` | MySQL connection string, there are two variants possible: Check **`Connections strings`** under this table. | `mysql://root@localhost/fivem`
`mysql_level` | Warn level used to print message in console, there are couble of options like: `info`, `debug`, `warn`, `error` or `fatal` | `warn`
`mysql_slow_query_warning` | When an query takes longer than the defined number, print an query warn message in console to let the server know that the executed query is slow | `500` (ms)

#### **Connections strings:**
**Variants:**
* `mysql://root:pass1234@localhost/fivem`
* `server=localhost;userid=root;password=pass1234;database=fivem`

### **Issues**
Make sure you provide all information possible when reporting an issue.

### **Changelog**
For a detailed changelog either check the commits or read [`https://github.com/ThymonA/fivem-mysql/releases`](https://github.com/ThymonA/fivem-mysql/releases)

### **Features**

* Async / Sync.
* It uses the [node-mysql2](https://github.com/sidorares/node-mysql2) library to provide a connection to your mysql server and is faster than the [mysql](https://github.com/mysqljs/mysql) library.
48 changes: 48 additions & 0 deletions example.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
-- 𝗙𝗶𝘃𝗲𝗠 𝗠𝘆𝗦𝗤𝗟 - 𝗠𝘆𝗦𝗤𝗟 𝗹𝗶𝗯𝗿𝗮𝗿𝘆 𝗳𝗼𝗿 𝗙𝗶𝘃𝗲𝗠
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
-- ➤ License: https://choosealicense.com/licenses/gpl-3.0/
-- ➤ GitHub: https://github.com/ThymonA/fivem-mysql/
-- ➤ Author: Thymon Arens <ThymonA>
-- ➤ Name: FiveM MySQL
-- ➤ Version: 1.0.0
-- ➤ Description: MySQL library made for FiveM
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
-- 𝗚𝗡𝗨 𝗚𝗲𝗻𝗲𝗿𝗮𝗹 𝗣𝘂𝗯𝗹𝗶𝗰 𝗟𝗶𝗰𝗲𝗻𝘀𝗲 𝘃𝟯.𝟬
--
-- ┃ Copyright (C) 2020 Thymon Arens <ThymonA>
--
-- ┃ This program is free software: you can redistribute it and/or modify
-- ┃ it under the terms of the GNU General Public License as published by
-- ┃ the Free Software Foundation, either version 3 of the License, or
-- ┃ (at your option) any later version.
--
-- ┃ This program is distributed in the hope that it will be useful,
-- ┃ but WITHOUT ANY WARRANTY; without even the implied warranty of
-- ┃ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- ┃ GNU General Public License for more details.
--
-- ┃ You should have received a copy of the GNU General Public License
-- ┃ along with this program. If not, see <https://www.gnu.org/licenses/>.
--

mysql:ready(function()
print(mysql:fetchScalar('SELECT @parameter', {
['parameter'] = 1
}))

print(mysql:fetchScalar('SELECT :parameter', {
['parameter'] = 1
}))

mysql:fetchAllAsync('SELECT * FROM `users` LIMIT 10', {}, function(results)
print(json.encode(results))
end)

print(json.encode(mysql:fetchAll('SELECT * FROM `users` LIMIT 10', {})))

mysql:fetchFirstAsync('SELECT * FROM `users` LIMIT 1', {}, function(results)
print(json.encode(results))
end)

print(json.encode(mysql:fetchFirst('SELECT * FROM `users` LIMIT 1', {})))
end)

0 comments on commit ec81100

Please sign in to comment.