Git Product home page Git Product logo

dbcp.clj's Introduction

Database Connection pool for Clojure

A jdbc connection pool written from scratch, using ThreadLocals, per Thread per connection. Works very good with http-kit server's thread pool model

Current semantic version: [http-kit/dbcp "0.1.0"].

wait, Is the API blocking (sync)? blocking = slow

Of course blocking! Blocking API is much much easier to use.

blocking = slow?

If you only have one thread, that's may be the case, you can do nothing but waiting for server if blocking. For Clojure, not the case, Clojure has multithreading, you can accept incoming request and wait for MySQL at the same time!

A SQL query can run more than 10s

It's time to double check your data and SQL statement. Non-blocking does not save you!

Feature

  • Clean and compact code: jar size is about ~11k
  • Fast, very fast.
  • The connection get atomatically closed when thread died.
  • Reconnect if closed

Usage

(:require [org.httpkit.dbcp :as db])

(db/use-database! "jdbc:mysql://localhost/test" "user" "password")

;; insert value
(db/insert-record :your_table {:column1 "value1"
                               :column2 "value2"
                               :column3 2})
=> {:generated_key 1} ;; mysql

;; update
(db/update-values :your_table ["column1 = ?" "value1"]
                  {:column1 "new-value"
                   :column3 1000})

;;query
(db/query "select * from your_table where column1 = ?" "value1")
=> ({:id 1 :column1 "new-value" :column2 "vlaue2" :column3 1000})

;; delete
(db/delete-rows :your_table ["column1 = ?" "value1"])

(db/close-database!)

Contact

Please use the GitHub issues page for feature suggestions, bug reports, or general discussions.

License

Copyright © 2012 Feng Shen. Distributed under the Apache License Version 2.0.

dbcp.clj's People

Contributors

shenfeng avatar oneto018 avatar

Watchers

 avatar James Cloos 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.