package

github.com/plambert/sqlite3_uri.cr

main / published Jul 8, 2025 / repository

Add support for reading/writing URIs as a String to sqlite3 databases

sqlite3_uri

Automatically convert URI instances to a String when writing to a sqlite3 database, and expect a String to convert back to a URI instance when reading from a ResultSet.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      sqlite3_uri:
        github: plambert/sqlite3_uri.cr
  2. Run shards install

Both db and sqlite3 will be brought in as dependencies by this shard; you don't need to specify them separately in your shard.yml.

Usage

require "sqlite3_uri"

DB.open "sqlite3:%3Amemory%3A" do |db|
  db.exec "CREATE TABLE urls (id INTEGER PRIMARY KEY, url TEXT NOT NULL)"
  ARGV.each do |url|
    db.exec "INSERT INTO urls (url) VALUES (?)", URI.parse url
  end

  urls = db.query_all "SELECT url FROM urls", as: URI
  puts urls.inspect
end

Contributing

  1. Fork it (https://github.com/plambert/sqlite3_uri.cr/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

API

This version publishes no documented types.