Main Navigation

Content

Working with Databases in Perl

Learn Perl Now!
And get a job doing Perl.

Introduction

There are many types of databases:

SQL Databases

The de-facto standard for working with SQL databases in Perl is DBI (short for Database Interface). It provides a unified way to perform SQL queries across many database backends: PostgreSQL, SQLite, MySQL (but see this page for some reasons why you may prefer a different system), Oracle, Firebird, and others.

Above DBI, people wrote some useful abstractions:

  • DBIx-Simple - an easy to use Object-Oriented Interface to DBI.

  • DBIx-Class - a powerful and convenient object-relational mapper. Use of the older and less philosophically sound Class-DBI is heavily discouraged.

  • Rose-DB-Object - another ORM - seems to be much less popular than DBIx-Class, but still actively maintained.

When working with databases make sure you avoid common pitfalls such as SQL injection vulnerabilities.

DBM Databases

  • The BerkeleyDB CPAN module is the standard module for working with Oracle Berkeley DB (formerly Sleepy Cat Berkeley DB) and maps the ANSI C library's API closely. Note that Berkeley DB is licensed under the Sleepycat License which is strong copyleft, and does not allow use for non-open-source programs.

  • Tokyo Cabinet - a modern, fast and powerful DBM implementation available under the LGPL license (which permits use in non-open-source projects). There’s also Kyoto Cabinet, which is claimed to be better, but is under the GPL license (which is strong copyleft and does not permit use in non-open-source projects).

  • LevelDB from Google, a fast key-value storage library, open-source under the new BSD license (which allows use for non-open-source programs). Has Perl bindings on CPAN called Tie-LevelDB.

    Note that its Wikipedia page cites some (possibly already fixed) past reliability problems.

  • DBM-Deep - a multi-level hash/array DBM that supports transactions. Reported to be slow, however.

XBase Databases

There seems to be an XBase module on CPAN . It seems to be pure-Perl, so it may be slow.

Distributed Databases (“No SQL”, etc.)

Recently, to meet the growing demand for data of some web sites, some people have switched to using non-centralised, non-SQL based databases that use a cluster of servers to implement a distributed data storage. This has been dubbed "No SQL". You most likely would prefer to use an SQL-based solution, which should be easily able to handle the data in your scope, but here is a list of some bindings for distributed databases just for completeness sake.

Share/Bookmark

Footer