项目作者: naqvis

项目描述 :
ODBC connector for Crystal
高级语言: Crystal
项目地址: git://github.com/naqvis/crystal-odbc.git
创建时间: 2020-04-06T17:36:50Z
项目社区:https://github.com/naqvis/crystal-odbc

开源协议:MIT License

下载


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

  1. 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.

  2. Add the dependency to your shard.yml:

    1. dependencies:
    2. odbc:
    3. github: naqvis/crystal-odbc
  3. Run shards install

Usage

  1. require "db"
  2. require "odbc"
  3. DB.open "odbc://DSN=dsn;UID=user;PWD=password" do |db|
  4. db.exec "create table contacts (name text, age integer)"
  5. db.exec "insert into contacts values (?, ?)", "John Doe", 30
  6. args = [] of DB::Any
  7. args << "Sarah"
  8. args << 33
  9. db.exec "insert into contacts values (?, ?)", args
  10. puts "max age:"
  11. puts db.scalar "select max(age) from contacts" # => 33
  12. puts "contacts:"
  13. db.query "select name, age from contacts order by age desc" do |rs|
  14. puts "#{rs.column_name(0)} (#{rs.column_name(1)})"
  15. # => name (age)
  16. rs.each do
  17. puts "#{rs.read(String)} (#{rs.read(Int32)})"
  18. # => Sarah (33)
  19. # => John Doe (30)
  20. end
  21. end
  22. end

refer to crystal-db for further usage instructions.

Development

To run all tests:

  1. crystal spec

Contributing

  1. Fork it (https://github.com/naqvis/crystal-odbc/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