Crystal Db

Common db api for crystal
Alternatives To Crystal Db
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Cockroach27,85550245 hours ago249August 06, 20215,824otherGo
CockroachDB - the open source, cloud-native distributed SQL database.
Mongo24,44315 hours ago22October 09, 202280otherC++
The MongoDB Database
Mysql13,6914,89211,2149 hours ago51April 25, 202374mpl-2.0Go
Go MySQL Driver is a MySQL driver for Go's (golang) database/sql package
Migrate12,2738156 days ago132June 11, 2023294otherGo
Database migrations. CLI and Golang library.
Node Mongodb Native9,848116,99511,023a day ago426July 06, 202320apache-2.0TypeScript
The Official MongoDB Node.js Driver
Yugabyte Db8,091
5 hours ago5,361otherC
YugabyteDB - the cloud native distributed SQL database for mission-critical applications.
Mongo Go Driver7,6416,0605 hours ago330August 02, 202310apache-2.0Go
The Official Golang driver for MongoDB
Go Sqlmock5,4251,336a month ago21June 28, 202075otherGo
Sql mock driver for golang to test database interactions
Postgres4,96631656 days ago38May 31, 202350unlicenseJavaScript
Postgres.js - The Fastest full featured PostgreSQL client for Node.js and Deno
Psycopg23,0346,0311,8938 hours ago21August 05, 202318otherC
PostgreSQL database adapter for the Python programming language
Alternatives To Crystal Db
Select To Compare


Alternative Project Comparisons
Readme

Build Status

crystal-db

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

Installation

If you are creating a shard that will work with any driver, then add crystal-db as a dependency in shard.yml:

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

If you are creating an application that will work with some specific driver(s), then add them in shard.yml:

dependencies:
  sqlite3:
    github: crystal-lang/crystal-sqlite3

crystal-db itself will be a nested dependency if drivers are included.

Note: Multiple drivers can be included in the same application.

Documentation

Usage

This shard only provides an abstract database API. In order to use it, a specific driver for the intended database has to be required as well:

The following example uses SQLite where ? indicates the arguments. If PostgreSQL is used $1, $2, etc. should be used. crystal-db does not interpret the statements.

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 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: 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:

  • [x] Support non prepared statements. #25
  • [x] Time data type. (implementation details depends on actual drivers)
  • [x] Data type extensibility. Allow each driver to extend the data types allowed.
  • [x] Transactions & nested transactions. #27
  • [x] Connection pool.
  • [x] Logging
  • [ ] 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
Popular Database Projects
Popular Driver Projects
Popular Data Storage Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Database
Driver
Transaction
Crystal