Resource:Datastore

From Multi Theft Auto: Wiki
Revision as of 06:05, 4 February 2020 by Shux (talk | contribs) (Created page with "{{Resource page}} DataStore allows you to store data (string/table) to a specific key in the database table. All you have to do is enter your database information in settings....")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

DataStore allows you to store data (string/table) to a specific key in the database table. All you have to do is enter your database information in settings.lua('sqlite' or 'mysql') and once connected you can use the datastore exported functions to store and/or get data from the db table. Very useful for beginner developers who lack experience with MySQL/SQLite.

Overview

Fairly easy to use.

Exported functions

getDatabase

Click to collapse [-]
Server

This function returns the database, if there is one at least.

exports['datastore']:getDatabase()

Returns

Returns the database connection if one was connected.

storeData

Click to collapse [-]
Server

This function stores data into a specific key in the connected database table.

exports['datastore']:storeData(string key, string/table value)

Required Arguments

  • string key: Key that the data is gonna be stored in
  • string/table value: Data to be stored in the key (tables are automatically stored as a string)

Returns

Returns true if the data was stored successfully.

getData

Click to collapse [-]
Server

This function gets the data stored in a specific key.

exports['datastore']:getData(string key)

Required Arguments

  • string key: Key that you would like to receive the data of.

Returns

Returns the data that was stored in the key if found. (converted tables to strings are automatically returned as tables)

getAllData

Click to collapse [-]
Server

This function gets all the keys and data stored in the connected database table.

exports['datastore']:getAllData()

Returns

Returns table of all the data received from the connected database table. Key names being the index value, value being the data of the key.

See Also

Resource: https://community.multitheftauto.com/?p=resources&s=details&id=17541