https://github.com/naqvis/crystal-odbc
ODBC connector for Crystal
https://github.com/naqvis/crystal-odbc
crystal crystal-db crystal-lang crystal-language crystal-odbc odbc odbc-driver unixodbc
Last synced: 23 days ago
JSON representation
ODBC connector for Crystal
- Host: GitHub
- URL: https://github.com/naqvis/crystal-odbc
- Owner: naqvis
- License: mit
- Created: 2020-04-06T17:36:50.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2023-07-24T13:06:10.000Z (almost 2 years ago)
- Last Synced: 2025-05-12T22:55:31.148Z (23 days ago)
- Topics: crystal, crystal-db, crystal-lang, crystal-language, crystal-odbc, odbc, odbc-driver, unixodbc
- Language: Crystal
- Size: 44.9 KB
- Stars: 12
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# crystal-odbc
Crystal ODBC driver implements [crystal-db](https://github.com/crystal-lang/crystal-db) API and is a wrapper around [unixODBC](http://www.unixodbc.org).
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`:
```yaml
dependencies:
odbc:
github: naqvis/crystal-odbc
```2. Run `shards install`
## Usage
```crystal
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", 30args = [] of DB::Any
args << "Sarah"
args << 33
db.exec "insert into contacts values (?, ?)", argsputs "max age:"
puts db.scalar "select max(age) from contacts" # => 33puts "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](https://github.com/crystal-lang/crystal-db) for further usage instructions.## Development
To run all tests:
```
crystal spec
```## Contributing
1. Fork it ()
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
- [Ali Naqvi](https://github.com/naqvis) - creator and maintainer