Crystal ODBC driver implements crystal-db API and is a wrapper around unixODBC.
unixODBC is an open-source ODBC-library that you can run on non-Windows platforms. It is the glue between odbc (this shard) and your SQL driver.
If you want to use odbc with unixODBC make sure you are running unixODBC 2.3.7!
-
Make sure you have unixODBC and SQL Driver (ODBC Driver/Connector) installed. Look into DBMS of your choice and find their ODBC driver installation instructions for your system.
-
Add the dependency to your
shard.yml
:dependencies: odbc: github: naqvis/crystal-odbc
-
Run
shards install
require "db"
require "odbc"
DB.open "odbc://DSN=dsn;UID=user;PWD=password" do |db|
db.exec "create table contacts (name text, 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
refer to crystal-db for further usage instructions.
To run all tests:
crystal spec
- Fork it (https://github.com/naqvis/crystal-odbc/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Ali Naqvi - creator and maintainer