As a programmer, you'll sooner or later need to store information in between invocations of a program. You can store this information in a text file and decode it with patterns, or you can store it in a Lua file and reloade it with
loadfile. But sometimes these methods aren't sufficiently fast, powerful, flexible, or scalable, in which case, you should store the information in a database. This chapter is a very brief introduction to databases and database systems. It will cover the following:
How data is organized in and retrieved from a database
SQL, the special-purpose language used to interact with databases
LuaSQL, a set of Lua bindings for a number of popular database systems
This section demonstrates some basic database concepts by having you implement a simple database and a system for retrieving data from it entirely in Lua.
Almost all databases in use today are what are known as relational databases because they are designed to work with relationships between things (the previous generation of databases was not good at this). In the following example, the things in question are customers, products, and orders of an imaginary business. The relational aspect is the fact that the orders are defined in terms of the products ordered and the customers who ordered them.