Accessing Databases
Crystal can work with a growing number[50] of SQL and NoSQL databases. Among them are SQLite, MySQL (or MariaDB), Postgres, MongoDB,[51] Redis,[52] and ReThinkDB.[53]
The Crystal team realized the importance of database access for a programming language, so they made a DB module in a package called crystal-db,[54] which provides a common unified database API. Crystal-db works seamlessly together with the SQLite, MySQL, and Postgres driver. You don’t need to explicitly require it. For other databases, you will need to add specific drivers.
Let’s illustrate the basic database operations using the SQLite sample database chinook.db. This database represents a music shop and contains tables artists and albums among others. Because ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access