crystal-odbc v0.2.1
crystal-odbc
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.
Version matters!
If you want to use odbc with unixODBC make sure you are running unixODBC 2.3.7!
Installation
-
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
Usage
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.
Development
To run all tests:
crystal spec
Contributing
- 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
Contributors
- Ali Naqvi - creator and maintainer
Repository
crystal-odbc
Owner
Statistic
- 11
- 1
- 2
- 0
- 1
- over 1 year ago
- April 6, 2020
License
MIT License
Links
Synced at
Sun, 17 Nov 2024 02:33:42 GMT
Languages