No description
Find a file
Lamonte e40c19d195 Updated MappingException and Rollback derive from DB::Error (#70)
Make all db exceptions derive from DB::Error
2017-11-07 23:18:43 -03:00
spec Release connection when unprepared statements can't be built 2017-09-07 19:21:36 -03:00
src Updated MappingException and Rollback derive from DB::Error (#70) 2017-11-07 23:18:43 -03:00
.gitignore update .gitignore 2016-12-26 11:09:19 -03:00
.travis.yml enforce tool format in .travis.yml 2016-09-06 12:58:40 -03:00
CHANGELOG.md bump version 0.4.2. Release notes. 2017-04-21 17:24:28 -03:00
LICENSE initial commit 2016-02-25 22:22:54 -03:00
README.md Add documentation links in README.md 2016-12-21 18:17:45 -03:00
shard.yml bump version 0.4.2. Release notes. 2017-04-21 17:24:28 -03:00

Build Status

crystal-db

Common db api for crystal. You will need to a specific driver to access a database.

Installation

Add this to your application's shard.yml:

dependencies:
  db:
    github: crystal-lang/crystal-db

Documentation

Usage

Since this is an abstract db api, it's usage is through a concrete database driver.

require "db"
require "sqlite3"

DB.open "sqlite3:./file.db" do |db|
  # When using the pg driver, use $1, $2, etc. instead of ?
  db.exec "create table contacts (name string, age integer)"
  db.exec "insert into contacts values (?, ?)", "John Doe", 30

  args = [] of DB::Any
  args << "Sarah"
  args << 33
  db.exec "insert into contacts values (?, ?)", args

  puts "max age:"
  puts db.scalar "select max(age) from contacts" # => 33

  puts "contacts:"
  db.query "select name, age from contacts order by age desc" do |rs|
    puts "#{rs.column_name(0)} (#{rs.column_name(1)})"
    # => name (age)
    rs.each do
      puts "#{rs.read(String)} (#{rs.read(Int32)})"
      # => Sarah (33)
      # => John Doe (30)
    end
  end
end

Roadmap

Issues not yet addressed

  • Support non prepared statements. #25
  • Time data type. (implementation details depends on actual drivers)
  • Data type extensibility. Allow each driver to extend the data types allowed.
  • Transactions & nested transactions. #27
  • Connection pool.
  • Direct access to IO to avoid memory allocation for blobs.

Contributing

  1. Fork it ( https://github.com/crystal-lang/crystal-db/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • bcardiff Brian J. Cardiff - creator, maintainer