Giter Site home page Giter Site logo

cl-dbi's Introduction

CL-DBI - Database independent interface for Common Lisp

Usage

(defvar *connection*
    (dbi:connect :mysql
                 :database-name "test"
                 :username "nobody"
                 :password "1234"))

(let ((query (dbi:prepare *connection*
               "SELECT * FROM somewhere WHERE flag = ? OR updated_at > ?"))
      (result (dbi:execute query 0 "2011-11-01")))
  (loop for row = (dbi:fetch result)
        while row
        ;; process "row".
        ))

Description

CL-DBI is intended to provide the same interface for each database.

Not only, you don't have to learn each API of databases anymore, but this layer is especially convenient when you want to use the different database by environment.

For example, your application had better to use efficient database such as MySQL on the production environment, but you may want to use SQLite3 on your machine. In that case, all what you have to do is only to rewrite calling dbi:connect.

Databases

  • SQLite3
  • PostgreSQL
  • MySQL

Installation

This library will be available on Quicklisp when ready to use.

API

User-Level API

  • connect [driver-name & params] => <dbi-connection>
  • disconnect [<dbi-connection>] => T or NIL
  • prepare [conn sql] => <dbi-query>
  • execute [query & params] => something
  • fetch [result] => a row data as plist
  • fetch-all [result] => a list of all row data
  • do-sql [conn sql & params]
  • list-all-drivers [] => (<dbi-driver> ..)
  • find-driver [driver-name] => <dbi-driver>
  • with-transaction [conn]
  • begin-transaction [conn]
  • commit [conn]
  • rollback [conn]

Driver-Level API

  • <dbi-driver>
  • <dbi-connection>
  • make-connection [driver params]
  • disconnect [<dbi-connection>] => T or NIL
  • prepare [conn sql] => <dbi-query>
  • fetch-using-connection [conn result] => a row data as plist
  • do-sql [conn sql & params]
  • execute-using-connection => something
  • escape-sql => string
  • begin-transaction [conn]
  • commit [conn]
  • rollback [conn]

Creating a new driver

Create a subclass of <dbi-driver> and implement following methods.

  • make-connection
  • disconnect [<dbi-connection>] => T or NIL
  • execute-using-connection

And these methods may be overrided if needed.

  • prepare
  • fetch-using-connection
  • do-sql
  • escape-sql

Dependencies

  • cl-annot
  • CL-Syntax
  • SPLIT-SEQUENCE
  • closer-mop

Author

Copyright

Copyright (c) 2011 Eitarow Fukamachi ([email protected])

License

Licensed under the LLGPL License.

cl-dbi's People

Contributors

fukamachi avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.