├── test ├── dummy │ ├── tmp │ │ ├── .keep │ │ ├── pids │ │ │ └── .keep │ │ ├── storage │ │ │ └── .keep │ │ └── local_secret.txt │ ├── storage │ │ ├── .keep │ │ └── test.sqlite3 │ ├── log │ │ └── .gitignore │ ├── app │ │ ├── controllers │ │ │ └── application_controller.rb │ │ ├── models │ │ │ └── application_record.rb │ │ └── views │ │ │ └── layouts │ │ │ └── application.html.erb │ ├── bin │ │ ├── rake │ │ ├── rails │ │ └── setup │ ├── config │ │ ├── environment.rb │ │ ├── boot.rb │ │ ├── routes.rb │ │ ├── database.yml │ │ ├── locales │ │ │ └── en.yml │ │ ├── application.rb │ │ ├── puma.rb │ │ └── environments │ │ │ └── test.rb │ └── config.ru ├── test_helper.rb ├── generators │ └── test_install.rb └── test_sqlpkg.rb ├── lib ├── sqlpkg │ ├── version.rb │ ├── railtie.rb │ ├── generators │ │ └── sqlpkg │ │ │ ├── templates │ │ │ └── initializer.rb │ │ │ └── install_generator.rb │ ├── upstream.rb │ └── commands.rb └── sqlpkg.rb ├── .standard.yml ├── .gitignore ├── bin ├── setup ├── console └── release ├── sig └── sqlpkg │ └── ruby.rbs ├── Rakefile ├── Gemfile ├── exe └── sqlpkg ├── .github └── workflows │ └── main.yml ├── CHANGELOG.md ├── LICENSE ├── sqlpkg.gemspec ├── LICENSE-DEPENDENCIES ├── rakelib └── package.rake ├── CODE_OF_CONDUCT.md ├── README.md └── Gemfile.lock /test/dummy/tmp/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/storage/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/tmp/pids/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/tmp/storage/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/dummy/log/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /lib/sqlpkg/version.rb: -------------------------------------------------------------------------------- 1 | module Sqlpkg 2 | VERSION = "0.3.0" 3 | end 4 | -------------------------------------------------------------------------------- /test/dummy/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | end 3 | -------------------------------------------------------------------------------- /test/dummy/storage/test.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fractaledmind/sqlpkg-ruby/HEAD/test/dummy/storage/test.sqlite3 -------------------------------------------------------------------------------- /test/dummy/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative "../config/boot" 3 | require "rake" 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /.standard.yml: -------------------------------------------------------------------------------- 1 | # For available configuration options, see: 2 | # https://github.com/standardrb/standard 3 | ruby_version: 2.6 4 | -------------------------------------------------------------------------------- /test/dummy/app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | primary_abstract_class 3 | end 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /_yardoc/ 4 | /coverage/ 5 | /doc/ 6 | /pkg/ 7 | /spec/reports/ 8 | /tmp/ 9 | /exe/*/sqlpkg 10 | .DS_Store 11 | -------------------------------------------------------------------------------- /test/dummy/tmp/local_secret.txt: -------------------------------------------------------------------------------- 1 | 2e674226836fd5b8d265fbc2088757c026b86086afb1ea213271ec09b432cce56122da2e7ba0ab5e70ab06f5b1b07fdf386b0cea6b28efce5afaa11d5aa1e76f -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /sig/sqlpkg/ruby.rbs: -------------------------------------------------------------------------------- 1 | module Sqlpkg 2 | module Ruby 3 | VERSION: String 4 | # See the writing guide of rbs: https://github.com/ruby/rbs#guides 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /test/dummy/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path("../config/application", __dir__) 3 | require_relative "../config/boot" 4 | require "rails/commands" 5 | -------------------------------------------------------------------------------- /test/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative "application" 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /test/dummy/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative "config/environment" 4 | 5 | run Rails.application 6 | Rails.application.load_server 7 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "bundler/gem_tasks" 4 | require "minitest/test_task" 5 | 6 | Minitest::TestTask.create 7 | 8 | require "standard/rake" 9 | 10 | task default: %i[test standard] 11 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | # Specify your gem's dependencies in sqlpkg-ruby.gemspec 6 | gemspec 7 | 8 | gem "rake", "~> 13.0" 9 | 10 | gem "minitest", "~> 5.16" 11 | 12 | gem "standard", "~> 1.3" 13 | -------------------------------------------------------------------------------- /test/dummy/config/boot.rb: -------------------------------------------------------------------------------- 1 | # Set up gems listed in the Gemfile. 2 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__) 3 | 4 | require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) 5 | $LOAD_PATH.unshift File.expand_path("../../../lib", __dir__) 6 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | require "bundler/setup" 5 | require "sqlpkg/ruby" 6 | 7 | # You can add fixtures and/or initialization code here to make experimenting 8 | # with your gem easier. You can also use a different console, if you like. 9 | 10 | require "irb" 11 | IRB.start(__FILE__) 12 | -------------------------------------------------------------------------------- /lib/sqlpkg/railtie.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "rails/railtie" 4 | 5 | module Sqlpkg 6 | class Railtie < ::Rails::Railtie 7 | # Load the `sqlpkg:install` generator into the host Rails app 8 | generators do 9 | require_relative "generators/sqlpkg/install_generator" 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /test/dummy/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dummy 5 | 6 | <%= csrf_meta_tags %> 7 | <%= csp_meta_tag %> 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | ENV["RAILS_ENV"] = "test" 4 | 5 | $LOAD_PATH.unshift File.expand_path("../lib", __dir__) 6 | 7 | require_relative "../test/dummy/config/environment" 8 | ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)] 9 | require "rails/test_help" 10 | require "sqlpkg" 11 | 12 | require "minitest/autorun" 13 | -------------------------------------------------------------------------------- /exe/sqlpkg: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby 2 | # because rubygems shims assume a gem's executables are Ruby 3 | 4 | require "sqlpkg/commands" 5 | 6 | begin 7 | command = [Sqlpkg::Commands.executable, *ARGV] 8 | puts command.inspect if ENV["DEBUG"] 9 | exec(*command) 10 | rescue Sqlpkg::Commands::UnsupportedPlatformException, Sqlpkg::Commands::ExecutableNotFoundException => e 11 | warn("ERROR: " + e.message) 12 | exit 1 13 | end 14 | -------------------------------------------------------------------------------- /lib/sqlpkg/generators/sqlpkg/templates/initializer.rb: -------------------------------------------------------------------------------- 1 | module SqlpkgLoader 2 | def configure_connection 3 | super 4 | 5 | @raw_connection.enable_load_extension(true) 6 | Dir.glob(".sqlpkg/**/*.{dll,so,dylib}") do |extension_path| 7 | @raw_connection.load_extension(extension_path) 8 | end 9 | @raw_connection.enable_load_extension(false) 10 | end 11 | end 12 | 13 | ActiveSupport.on_load(:active_record_sqlite3adapter) do 14 | prepend SqlpkgLoader 15 | end 16 | -------------------------------------------------------------------------------- /test/dummy/config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html 3 | 4 | # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. 5 | # Can be used by load balancers and uptime monitors to verify that the app is live. 6 | get "up" => "rails/health#show", :as => :rails_health_check 7 | 8 | # Defines the root path route ("/") 9 | # root "posts#index" 10 | end 11 | -------------------------------------------------------------------------------- /lib/sqlpkg/upstream.rb: -------------------------------------------------------------------------------- 1 | module Sqlpkg 2 | # constants describing the upstream sqlpkg-cli project 3 | module Upstream 4 | VERSION = "0.3.0" 5 | 6 | # rubygems platform name => upstream release filename 7 | NATIVE_PLATFORMS = { 8 | "arm64-darwin" => "sqlpkg-cli_#{VERSION}_darwin_arm64.tar.gz", 9 | "arm64-linux" => "sqlpkg-cli_#{VERSION}_linux_arm64.tar.gz", 10 | "x86_64-darwin" => "sqlpkg-cli_#{VERSION}_darwin_amd64.tar.gz", 11 | "x86_64-linux" => "sqlpkg-cli_#{VERSION}_linux_amd64.tar.gz" 12 | } 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Ruby 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | name: Ruby ${{ matrix.ruby }} 12 | strategy: 13 | matrix: 14 | ruby: 15 | - '3.2' 16 | - '3.3' 17 | - '3.4' 18 | 19 | steps: 20 | - uses: actions/checkout@v4 21 | - name: Set up Ruby 22 | uses: ruby/setup-ruby@v1 23 | with: 24 | ruby-version: ${{ matrix.ruby }} 25 | bundler-cache: true 26 | - name: Run the default task 27 | run: bundle exec rake 28 | -------------------------------------------------------------------------------- /bin/release: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | VERSION=$1 4 | 5 | if [ -z "$VERSION" ]; then 6 | echo "Usage: $0 " 7 | exit 1 8 | fi 9 | 10 | printf "module Sqlpkg\n VERSION = \"$VERSION\"\nend\n" > ./lib/sqlpkg/version.rb 11 | bundle 12 | git add Gemfile.lock lib/sqlpkg/version.rb CHANGELOG.md 13 | git commit -m "Bump version for $VERSION" 14 | git push 15 | git tag v$VERSION 16 | git push --tags 17 | 18 | rake package 19 | for gem in pkg/sqlpkg-$VERSION*.gem ; do 20 | gem push "$gem" --host https://rubygems.org 21 | if [ $? -eq 0 ]; then 22 | rm "$gem" 23 | rm -rf "${gem/.gem/}" 24 | fi 25 | done 26 | -------------------------------------------------------------------------------- /test/dummy/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite. Versions 3.8.0 and up are supported. 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem "sqlite3" 6 | # 7 | default: &default 8 | adapter: sqlite3 9 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 10 | timeout: 5000 11 | 12 | development: 13 | <<: *default 14 | database: storage/development.sqlite3 15 | 16 | # Warning: The database defined as "test" will be erased and 17 | # re-generated from your development database when you run "rake". 18 | # Do not set this db to the same as development or production. 19 | test: 20 | <<: *default 21 | database: storage/test.sqlite3 22 | 23 | production: 24 | <<: *default 25 | database: storage/production.sqlite3 26 | -------------------------------------------------------------------------------- /test/generators/test_install.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "test_helper" 4 | require "rails/generators" 5 | require "sqlpkg/generators/sqlpkg/install_generator" 6 | 7 | class SqlpkgGeneratorTest < Rails::Generators::TestCase 8 | tests Sqlpkg::Generators::InstallGenerator 9 | destination File.expand_path("../tmp", __dir__) 10 | 11 | setup :prepare_destination 12 | 13 | def after_teardown 14 | FileUtils.rm_rf destination_root 15 | super 16 | end 17 | 18 | test "should generate project scope directory" do 19 | run_generator 20 | 21 | assert_directory ".sqlpkg" 22 | end 23 | 24 | test "should generate lockfile" do 25 | run_generator 26 | 27 | assert_file "sqlpkg.lock" 28 | end 29 | 30 | test "should generate initializer" do 31 | run_generator 32 | 33 | assert_file "config/initializers/sqlpkg.rb" do |content| 34 | assert_match "@raw_connection.load_extension(extension_path)", content 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /test/test_sqlpkg.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "test_helper" 4 | 5 | class TestSqlpkg < Minitest::Test 6 | def test_that_it_has_a_version_number 7 | refute_nil ::Sqlpkg::VERSION 8 | end 9 | 10 | def test_path_for_when_glob_returns_paths 11 | path = "./.sqlpkg/nalgeon/uuid/uuid.dylib" 12 | Dir.stub :glob, [path] do 13 | assert_equal path, Sqlpkg.path_for("nalgeon/uuid") 14 | end 15 | end 16 | 17 | def test_path_for_when_glob_returns_empty_array 18 | assert_raises Sqlpkg::ExtensionNotInstalledError do 19 | Sqlpkg.path_for("nalgeon/uuid") 20 | end 21 | end 22 | 23 | def test_accessor_when_glob_returns_paths 24 | path = "./.sqlpkg/nalgeon/uuid/uuid.dylib" 25 | Dir.stub :glob, [path] do 26 | assert_equal path, Sqlpkg["nalgeon/uuid"] 27 | end 28 | end 29 | 30 | def test_accessor_when_glob_returns_empty_array 31 | assert_raises Sqlpkg::ExtensionNotInstalledError do 32 | Sqlpkg["nalgeon/uuid"] 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /lib/sqlpkg/generators/sqlpkg/install_generator.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require "rails/generators/base" 4 | 5 | module Sqlpkg 6 | module Generators 7 | class InstallGenerator < ::Rails::Generators::Base 8 | source_root File.expand_path("templates", __dir__) 9 | 10 | def ensure_sqlpkg_project_scope_directory 11 | empty_directory ".sqlpkg" 12 | end 13 | 14 | def create_gitignore_in_sqlpkg_project_scope_directory 15 | create_file ".sqlpkg/.gitignore", <<~CONTENT 16 | * 17 | !.gitignore 18 | CONTENT 19 | end 20 | 21 | def create_empty_sqlpkg_lockfile 22 | create_file "sqlpkg.lock", <<~CONTENT 23 | { 24 | "packages": {} 25 | } 26 | CONTENT 27 | end 28 | 29 | def copy_initializer_file 30 | return if defined? EnhancedSQLite3::Adapter 31 | 32 | template "initializer.rb", "config/initializers/sqlpkg.rb" 33 | end 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /test/dummy/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization and 2 | # are automatically loaded by Rails. If you want to use locales other than 3 | # English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t "hello" 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t("hello") %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more about the API, please read the Rails Internationalization guide 20 | # at https://guides.rubyonrails.org/i18n.html. 21 | # 22 | # Be aware that YAML interprets the following case-insensitive strings as 23 | # booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings 24 | # must be quoted to be interpreted as strings. For example: 25 | # 26 | # en: 27 | # "yes": yup 28 | # enabled: "ON" 29 | 30 | en: 31 | hello: "Hello world" 32 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [Unreleased] 2 | 3 | ## [0.3.0] - 2025-06-04 4 | 5 | - Update the `sqlpkg` upstream version to v0.3.0 6 | - Fix `path_for` not resolving correctly in Rails 8 apps ([@mkempe](https://github.com/fractaledmind/sqlpkg-ruby/pull/6)) 7 | 8 | ## [0.2.3.2] - 2024-05-05 9 | 10 | - Add method to resolve path to an installed extension 11 | 12 | ## [0.2.3.1] - 2024-05-05 13 | 14 | - Only print the command if the DEBUG env variable is set 15 | 16 | ## [0.2.3] - 2024-05-05 17 | 18 | - Only create the initializer if the enhanced adapter gem isn't installed 19 | - Update the `sqlpkg` upstream version to v0.2.3 20 | 21 | ## [0.2.2] - 2023-12-24 22 | 23 | - ... actually fix the `sqlpkg:install` generator by committing the code 24 | - Ensure `sqlpkg.lock` has the proper content to work with the installer 25 | 26 | ## [0.2.1] - 2023-12-24 27 | 28 | - Fix `sqlpkg:install` generator by actually requiring it 29 | 30 | ## [0.2.0] - 2023-12-24 31 | 32 | - Add `sqlpkg:install` railtie generator 33 | 34 | ## [0.1.1] - 2023-12-23 35 | 36 | - Fix the `exe/sqlpkg` script 37 | 38 | ## [0.1.0] - 2023-12-20 39 | 40 | - Initial release 41 | -------------------------------------------------------------------------------- /test/dummy/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require "fileutils" 3 | 4 | # path to your application root. 5 | APP_ROOT = File.expand_path("..", __dir__) 6 | 7 | def system!(*args) 8 | system(*args, exception: true) 9 | end 10 | 11 | FileUtils.chdir APP_ROOT do 12 | # This script is a way to set up or update your development environment automatically. 13 | # This script is idempotent, so that you can run it at any time and get an expectable outcome. 14 | # Add necessary setup steps to this file. 15 | 16 | puts "== Installing dependencies ==" 17 | system! "gem install bundler --conservative" 18 | system("bundle check") || system!("bundle install") 19 | 20 | # puts "\n== Copying sample files ==" 21 | # unless File.exist?("config/database.yml") 22 | # FileUtils.cp "config/database.yml.sample", "config/database.yml" 23 | # end 24 | 25 | puts "\n== Preparing database ==" 26 | system! "bin/rails db:prepare" 27 | 28 | puts "\n== Removing old logs and tempfiles ==" 29 | system! "bin/rails log:clear tmp:clear" 30 | 31 | puts "\n== Restarting application server ==" 32 | system! "bin/rails restart" 33 | end 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2023 Stephen Margheim 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /sqlpkg.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require_relative "lib/sqlpkg/version" 4 | 5 | Gem::Specification.new do |spec| 6 | spec.name = "sqlpkg" 7 | spec.version = Sqlpkg::VERSION 8 | spec.authors = ["Stephen Margheim"] 9 | spec.email = ["stephen.margheim@gmail.com"] 10 | 11 | spec.summary = "Integrate sqlpkg with the RubyGems infrastructure." 12 | spec.homepage = "https://github.com/fractaledmind/sqlpkg-ruby" 13 | spec.license = "MIT" 14 | spec.required_ruby_version = ">= 3.0.0" 15 | 16 | spec.metadata = { 17 | "homepage_uri" => spec.homepage, 18 | "rubygems_mfa_required" => "true", 19 | "source_code_uri" => spec.homepage, 20 | "changelog_uri" => "https://github.com/fractaledmind/sqlpkg-ruby/CHANGELOG.md" 21 | } 22 | 23 | spec.files = Dir["lib/**/*", "LICENSE", "Rakefile", "README.md"] 24 | spec.bindir = "exe" 25 | spec.executables << "sqlpkg" 26 | 27 | # Uncomment to register a new dependency of your gem 28 | # spec.add_dependency "example-gem", "~> 1.0" 29 | spec.add_development_dependency "rubyzip" 30 | spec.add_development_dependency "rails" 31 | spec.add_development_dependency "sqlite3" 32 | 33 | # For more information and examples about making a new gem, check out our 34 | # guide at: https://bundler.io/guides/creating_gem.html 35 | end 36 | -------------------------------------------------------------------------------- /LICENSE-DEPENDENCIES: -------------------------------------------------------------------------------- 1 | sqlpkg-ruby may redistribute executables from the https://github.com/nalgeon/sqlpkg project 2 | 3 | The license for that software can be found at https://github.com/nalgeon/sqlpkg/blob/main/LICENSE which is reproduced here for your convenience: 4 | 5 | MIT License 6 | 7 | Copyright (c) 2023+ Anton Zhiyanov 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy 10 | of this software and associated documentation files (the "Software"), to deal 11 | in the Software without restriction, including without limitation the rights 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | copies of the Software, and to permit persons to whom the Software is 14 | furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | -------------------------------------------------------------------------------- /lib/sqlpkg.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Sqlpkg 4 | DIR = ".sqlpkg" 5 | FILE_PATTERN = "*.{dylib,so,dll}" 6 | 7 | Error = Class.new(StandardError) 8 | ExtensionNotInstalledError = Class.new(Error) 9 | 10 | class << self 11 | # File path for identified extension 12 | # => "./.sqlpkg/nalgeon/uuid/uuid.dylib" 13 | def path_for(identifier) 14 | path_glob = File.join(file_dir, identifier, FILE_PATTERN) 15 | path = Dir.glob(path_glob).first 16 | 17 | path || raise(ExtensionNotInstalledError, "No extension found for identifier: #{identifier}") 18 | end 19 | alias_method :[], :path_for 20 | 21 | # The directory where `sqlpkg` stores installed extensions 22 | # => "#{Rails.root}/.sqlpkg" or "./.sqlpkg" 23 | def file_dir 24 | if defined?(Rails) && Rails.respond_to?(:root) && Dir.exist?(Rails.root.join(DIR)) 25 | Rails.root.join(DIR) 26 | else 27 | File.join(__dir__, DIR) 28 | end 29 | end 30 | 31 | # List of file paths for all installed extensions 32 | # => ["./.sqlpkg/asg017/ulid/ulid0.dylib", "./.sqlpkg/nalgeon/uuid/uuid.dylib"] 33 | def installed_extension_paths 34 | Dir.glob File.join(file_dir, "**", FILE_PATTERN) 35 | end 36 | end 37 | end 38 | 39 | require_relative "sqlpkg/version" 40 | require_relative "sqlpkg/upstream" 41 | require_relative "sqlpkg/commands" 42 | require_relative "sqlpkg/railtie" if defined?(::Rails::Railtie) 43 | -------------------------------------------------------------------------------- /test/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative "boot" 2 | 3 | require "rails" 4 | # Pick the frameworks you want: 5 | require "active_model/railtie" 6 | # require "active_job/railtie" 7 | require "active_record/railtie" 8 | # require "active_storage/engine" 9 | require "action_controller/railtie" 10 | # require "action_mailer/railtie" 11 | # require "action_mailbox/engine" 12 | # require "action_text/engine" 13 | require "action_view/railtie" 14 | # require "action_cable/engine" 15 | require "rails/test_unit/railtie" 16 | 17 | # Require the gems listed in Gemfile, including any gems 18 | # you've limited to :test, :development, or :production. 19 | Bundler.require(*Rails.groups) 20 | 21 | module Dummy 22 | class Application < Rails::Application 23 | config.load_defaults Rails::VERSION::STRING.to_f 24 | 25 | # For compatibility with applications that use this config 26 | config.action_controller.include_all_helpers = false 27 | 28 | # Please, add to the `ignore` list any other `lib` subdirectories that do 29 | # not contain `.rb` files, or that should not be reloaded or eager loaded. 30 | # Common ones are `templates`, `generators`, or `middleware`, for example. 31 | config.autoload_lib(ignore: %w[assets tasks]) 32 | 33 | # Configuration for the application, engines, and railties goes here. 34 | # 35 | # These settings can be overridden in specific environments using the files 36 | # in config/environments, which are processed later. 37 | # 38 | # config.time_zone = "Central Time (US & Canada)" 39 | # config.eager_load_paths << Rails.root.join("extras") 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /test/dummy/config/puma.rb: -------------------------------------------------------------------------------- 1 | # This configuration file will be evaluated by Puma. The top-level methods that 2 | # are invoked here are part of Puma's configuration DSL. For more information 3 | # about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. 4 | 5 | # Puma can serve each request in a thread from an internal thread pool. 6 | # The `threads` method setting takes two numbers: a minimum and maximum. 7 | # Any libraries that use thread pools should be configured to match 8 | # the maximum value specified for Puma. Default is set to 5 threads for minimum 9 | # and maximum; this matches the default thread size of Active Record. 10 | max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } 11 | min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } 12 | threads min_threads_count, max_threads_count 13 | 14 | # Specifies that the worker count should equal the number of processors in production. 15 | if ENV["RAILS_ENV"] == "production" 16 | require "concurrent-ruby" 17 | worker_count = Integer(ENV.fetch("WEB_CONCURRENCY") { Concurrent.physical_processor_count }) 18 | workers worker_count if worker_count > 1 19 | end 20 | 21 | # Specifies the `worker_timeout` threshold that Puma will use to wait before 22 | # terminating a worker in development environments. 23 | worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" 24 | 25 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000. 26 | port ENV.fetch("PORT") { 3000 } 27 | 28 | # Specifies the `environment` that Puma will run in. 29 | environment ENV.fetch("RAILS_ENV") { "development" } 30 | 31 | # Specifies the `pidfile` that Puma will use. 32 | pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } 33 | 34 | # Allow puma to be restarted by `bin/rails restart` command. 35 | plugin :tmp_restart 36 | -------------------------------------------------------------------------------- /test/dummy/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | require "active_support/core_ext/integer/time" 2 | 3 | # The test environment is used exclusively to run your application's 4 | # test suite. You never need to work with it otherwise. Remember that 5 | # your test database is "scratch space" for the test suite and is wiped 6 | # and recreated between test runs. Don't rely on the data there! 7 | 8 | Rails.application.configure do 9 | # Settings specified here will take precedence over those in config/application.rb. 10 | 11 | # While tests run files are not watched, reloading is not necessary. 12 | config.enable_reloading = false 13 | 14 | # Eager loading loads your entire application. When running a single test locally, 15 | # this is usually not necessary, and can slow down your test suite. However, it's 16 | # recommended that you enable it in continuous integration systems to ensure eager 17 | # loading is working properly before deploying your code. 18 | config.eager_load = ENV["CI"].present? 19 | 20 | # Configure public file server for tests with Cache-Control for performance. 21 | config.public_file_server.enabled = true 22 | config.public_file_server.headers = { 23 | "Cache-Control" => "public, max-age=#{1.hour.to_i}" 24 | } 25 | 26 | # Show full error reports and disable caching. 27 | config.consider_all_requests_local = true 28 | config.action_controller.perform_caching = false 29 | config.cache_store = :null_store 30 | 31 | # Render exception templates for rescuable exceptions and raise for other exceptions. 32 | config.action_dispatch.show_exceptions = :rescuable 33 | 34 | # Disable request forgery protection in test environment. 35 | config.action_controller.allow_forgery_protection = false 36 | 37 | # Store uploaded files on the local file system in a temporary directory. 38 | # config.active_storage.service = :test 39 | 40 | # config.action_mailer.perform_caching = false 41 | 42 | # Tell Action Mailer not to deliver emails to the real world. 43 | # The :test delivery method accumulates sent emails in the 44 | # ActionMailer::Base.deliveries array. 45 | # config.action_mailer.delivery_method = :test 46 | 47 | # Print deprecation notices to the stderr. 48 | config.active_support.deprecation = :stderr 49 | 50 | # Raise exceptions for disallowed deprecations. 51 | config.active_support.disallowed_deprecation = :raise 52 | 53 | # Tell Active Support which deprecation messages to disallow. 54 | config.active_support.disallowed_deprecation_warnings = [] 55 | 56 | # Raises error for missing translations. 57 | # config.i18n.raise_on_missing_translations = true 58 | 59 | # Annotate rendered view with file names. 60 | # config.action_view.annotate_rendered_view_with_filenames = true 61 | 62 | # Raise error when a before_action's only/except options reference missing actions 63 | config.action_controller.raise_on_missing_callback_actions = true 64 | end 65 | -------------------------------------------------------------------------------- /lib/sqlpkg/commands.rb: -------------------------------------------------------------------------------- 1 | require_relative "upstream" 2 | 3 | module Sqlpkg 4 | module Commands 5 | DEFAULT_DIR = File.expand_path(File.join(__dir__, "..", "..", "exe")) 6 | GEM_NAME = "sqlpkg" 7 | 8 | # raised when the host platform is not supported by upstream sqlpkg's binary releases 9 | class UnsupportedPlatformException < StandardError 10 | end 11 | 12 | # raised when the sqlpkg executable could not be found where we expected it to be 13 | class ExecutableNotFoundException < StandardError 14 | end 15 | 16 | # raised when SQLPKG_INSTALL_DIR does not exist 17 | class DirectoryNotFoundException < StandardError 18 | end 19 | 20 | def self.platform 21 | [:cpu, :os].map { |m| Gem::Platform.local.send(m) }.join("-") 22 | end 23 | 24 | def self.executable(exe_path: DEFAULT_DIR) 25 | sqlpkg_install_dir = ENV["SQLPKG_INSTALL_DIR"] 26 | if sqlpkg_install_dir 27 | if File.directory?(sqlpkg_install_dir) 28 | warn "NOTE: using SQLPKG_INSTALL_DIR to find sqlpkg executable: #{sqlpkg_install_dir}" 29 | exe_path = sqlpkg_install_dir 30 | exe_file = File.expand_path(File.join(sqlpkg_install_dir, "sqlpkg")) 31 | else 32 | raise DirectoryNotFoundException, <<~MESSAGE 33 | SQLPKG_INSTALL_DIR is set to #{sqlpkg_install_dir}, but that directory does not exist. 34 | MESSAGE 35 | end 36 | else 37 | if Sqlpkg::Upstream::NATIVE_PLATFORMS.keys.none? { |p| Gem::Platform.match_gem?(Gem::Platform.new(p), GEM_NAME) } 38 | raise UnsupportedPlatformException, <<~MESSAGE 39 | sqlpkg-ruby does not support the #{platform} platform 40 | Please install sqlpkg following instructions at https://github.com/nalgeon/sqlpkg-cli#download-and-install-preferred-method 41 | MESSAGE 42 | end 43 | 44 | exe_file = Dir.glob(File.expand_path(File.join(exe_path, "*", "sqlpkg"))).find do |f| 45 | Gem::Platform.match_gem?(Gem::Platform.new(File.basename(File.dirname(f))), GEM_NAME) 46 | end 47 | end 48 | 49 | if exe_file.nil? || !File.exist?(exe_file) 50 | raise ExecutableNotFoundException, <<~MESSAGE 51 | Cannot find the sqlpkg executable for #{platform} in #{exe_path} 52 | 53 | If you're using bundler, please make sure you're on the latest bundler version: 54 | 55 | gem install bundler 56 | bundle update --bundler 57 | 58 | Then make sure your lock file includes this platform by running: 59 | 60 | bundle lock --add-platform #{platform} 61 | bundle install 62 | 63 | See `bundle lock --help` output for details. 64 | 65 | If you're still seeing this message after taking those steps, try running 66 | `bundle config` and ensure `force_ruby_platform` isn't set to `true`. See 67 | https://github.com/fractaledmind/sqlpkg-ruby#check-bundle_force_ruby_platform 68 | for more details. 69 | MESSAGE 70 | end 71 | 72 | exe_file 73 | end 74 | end 75 | end 76 | -------------------------------------------------------------------------------- /rakelib/package.rake: -------------------------------------------------------------------------------- 1 | # 2 | # Rake tasks to manage native gem packages with binary executables from nalgeon/sqlpkg-cli 3 | # 4 | # TL;DR: run "rake package" 5 | # 6 | # The native platform gems (defined by Sqlpkg::Upstream::NATIVE_PLATFORMS) will each contain 7 | # two files in addition to what the vanilla ruby gem contains: 8 | # 9 | # exe/ 10 | # ├── sqlpkg # generic ruby script to find and run the binary 11 | # └── / 12 | # └── sqlpkg # the sqlpkg binary executable 13 | # 14 | # The ruby script `exe/sqlpkg` is installed into the user's path, and it simply locates the 15 | # binary and executes it. Note that this script is required because rubygems requires that 16 | # executables declared in a gemspec must be Ruby scripts. 17 | # 18 | # As a concrete example, an x86_64-linux system will see these files on disk after installing 19 | # sqlpkg-0.x.x-x86_64-linux.gem: 20 | # 21 | # exe/ 22 | # ├── sqlpkg 23 | # └── x86_64-linux/ 24 | # └── sqlpkg 25 | # 26 | # So the full set of gem files created will be: 27 | # 28 | # - pkg/sqlpkg-1.0.0.gem 29 | # - pkg/sqlpkg-1.0.0-arm64-linux.gem 30 | # - pkg/sqlpkg-1.0.0-arm64-darwin.gem 31 | # - pkg/sqlpkg-1.0.0-x86_64-darwin.gem 32 | # - pkg/sqlpkg-1.0.0-x86_64-linux.gem 33 | # 34 | # Note that in addition to the native gems, a vanilla "ruby" gem will also be created without 35 | # either the `exe/sqlpkg` script or a binary executable present. 36 | # 37 | # 38 | # New rake tasks created: 39 | # 40 | # - rake gem:ruby # Build the ruby gem 41 | # - rake gem:arm64-linux # Build the aarch64-linux gem 42 | # - rake gem:arm64-darwin # Build the arm64-darwin gem 43 | # - rake gem:x86_64-darwin # Build the x86_64-darwin gem 44 | # - rake gem:x86_64-linux # Build the x86_64-linux gem 45 | # - rake download # Download all sqlpkg binaries 46 | # 47 | # Modified rake tasks: 48 | # 49 | # - rake gem # Build all the gem files 50 | # - rake package # Build all the gem files (same as `gem`) 51 | # - rake repackage # Force a rebuild of all the gem files 52 | # 53 | # Note also that the binary executables will be lazily downloaded when needed, but you can 54 | # explicitly download them with the `rake download` command. 55 | # 56 | require "rubygems/package" 57 | require "rubygems/package_task" 58 | require "open-uri" 59 | require "zlib" 60 | require "zip" 61 | require_relative "../lib/sqlpkg/upstream" 62 | 63 | def sqlpkg_download_url(filename) 64 | "https://github.com/nalgeon/sqlpkg-cli/releases/download/#{Sqlpkg::Upstream::VERSION}/#{filename}" 65 | end 66 | 67 | SQLPKG_RAILS_GEMSPEC = Bundler.load_gemspec("sqlpkg.gemspec") 68 | 69 | gem_path = Gem::PackageTask.new(SQLPKG_RAILS_GEMSPEC).define 70 | desc "Build the ruby gem" 71 | task "gem:ruby" => [gem_path] 72 | 73 | exepaths = [] 74 | Sqlpkg::Upstream::NATIVE_PLATFORMS.each do |platform, filename| 75 | SQLPKG_RAILS_GEMSPEC.dup.tap do |gemspec| 76 | exedir = File.join(gemspec.bindir, platform) # "exe/x86_64-linux" 77 | exepath = File.join(exedir, "sqlpkg") # "exe/x86_64-linux/sqlpkg" 78 | exepaths << exepath 79 | 80 | # modify a copy of the gemspec to include the native executable 81 | gemspec.platform = platform 82 | gemspec.files += [exepath, "LICENSE-DEPENDENCIES"] 83 | 84 | # create a package task 85 | gem_path = Gem::PackageTask.new(gemspec).define 86 | desc "Build the #{platform} gem" 87 | task "gem:#{platform}" => [gem_path] 88 | 89 | directory exedir 90 | file exepath => [exedir] do 91 | release_url = sqlpkg_download_url(filename) 92 | warn "Downloading #{exepath} from #{release_url} ..." 93 | 94 | # lazy, but fine for now. 95 | URI.open(release_url) do |remote| # standard:disable Security/Open 96 | if release_url.end_with?(".zip") 97 | Zip::File.open_buffer(remote) do |zip_file| 98 | zip_file.extract("sqlpkg", exepath) 99 | end 100 | elsif release_url.end_with?(".gz") 101 | Zlib::GzipReader.wrap(remote) do |gz| 102 | Gem::Package::TarReader.new(gz) do |reader| 103 | reader.seek("sqlpkg") do |file| 104 | File.binwrite(exepath, file.read) 105 | end 106 | end 107 | end 108 | end 109 | end 110 | FileUtils.chmod(0o755, exepath, verbose: true) 111 | end 112 | end 113 | end 114 | 115 | desc "Download all sqlpkg binaries" 116 | task "download" => exepaths 117 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 8 | 9 | ## Our Standards 10 | 11 | Examples of behavior that contributes to a positive environment for our community include: 12 | 13 | * Demonstrating empathy and kindness toward other people 14 | * Being respectful of differing opinions, viewpoints, and experiences 15 | * Giving and gracefully accepting constructive feedback 16 | * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 17 | * Focusing on what is best not just for us as individuals, but for the overall community 18 | 19 | Examples of unacceptable behavior include: 20 | 21 | * The use of sexualized language or imagery, and sexual attention or 22 | advances of any kind 23 | * Trolling, insulting or derogatory comments, and personal or political attacks 24 | * Public or private harassment 25 | * Publishing others' private information, such as a physical or email 26 | address, without their explicit permission 27 | * Other conduct which could reasonably be considered inappropriate in a 28 | professional setting 29 | 30 | ## Enforcement Responsibilities 31 | 32 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. 33 | 34 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. 35 | 36 | ## Scope 37 | 38 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. 39 | 40 | ## Enforcement 41 | 42 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at stephen.margheim@gmail.com. All complaints will be reviewed and investigated promptly and fairly. 43 | 44 | All community leaders are obligated to respect the privacy and security of the reporter of any incident. 45 | 46 | ## Enforcement Guidelines 47 | 48 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: 49 | 50 | ### 1. Correction 51 | 52 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. 53 | 54 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. 55 | 56 | ### 2. Warning 57 | 58 | **Community Impact**: A violation through a single incident or series of actions. 59 | 60 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. 61 | 62 | ### 3. Temporary Ban 63 | 64 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. 65 | 66 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. 67 | 68 | ### 4. Permanent Ban 69 | 70 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. 71 | 72 | **Consequence**: A permanent ban from any sort of public interaction within the community. 73 | 74 | ## Attribution 75 | 76 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, 77 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 78 | 79 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). 80 | 81 | [homepage]: https://www.contributor-covenant.org 82 | 83 | For answers to common questions about this code of conduct, see the FAQ at 84 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sqlpkg-ruby 2 | 3 | [sqlpkg](https://sqlpkg.org/) is the (unofficial) SQLite package registry. This gem provides a Ruby interface to [its CLI](https://github.com/nalgeon/sqlpkg-cli). 4 | 5 | ## Installation 6 | 7 | Install the gem and add to the application's Gemfile by executing: 8 | ```shell 9 | bundle add sqlpkg 10 | ``` 11 | 12 | If bundler is not being used to manage dependencies, install the gem by executing: 13 | ```shell 14 | gem install sqlpkg 15 | ``` 16 | 17 | After installing the gem, run the installer: 18 | ```shell 19 | rails generate sqlpkg:install 20 | ``` 21 | 22 | The installer does three things: 23 | 24 | 1. creates an empty `.sqlpkg/` directory, which ensures that `sqlpkg` will run in "project scope" and not "global scope" (see [the `sqlpkg-cli` README](https://github.com/nalgeon/sqlpkg-cli#project-vs-global-scope) for more information) 25 | 2. creates an empty `sqlpkg.lock` file, which `sqlpkg` will use to store information about the installed packages (see [the `sqlpkg-cli` README](https://github.com/nalgeon/sqlpkg-cli#lockfile) for more information) 26 | 3. creates an initializer file at `config/initializers/sqlpkg.rb` which will patch the `SQLite3Adapter` to automatically load the extensions installed in the `.sqlpkg/` directory whenever the database is opened 27 | 28 | Once properly integrated into your Rails application, you can install any extension listed on [the `sqlpkg` registry](https://sqlpkg.org/all/) by executing: 29 | ```shell 30 | bundle exec sqlpkg install PACKAGE_IDENTIFIER 31 | ``` 32 | 33 | When exploring the [the `sqlpkg` registry](https://sqlpkg.org/all/), the `PACKAGE_IDENTIFIER` needed to install an extension is the title found in the cards, always in `owner/name` format. 34 | 35 | This gem wraps the standalone executable version of the [sqlpkg-cli](https://github.com/nalgeon/sqlpkg-cli#download-and-install-preferred-method). These executables are platform specific, so there are actually separate underlying gems per platform, but the correct gem will automatically be picked for your platform. 36 | 37 | Supported platforms are: 38 | 39 | * arm64-darwin (macos-arm64) 40 | * x86_64-darwin (macos-x64) 41 | * arm64-linux (linux-arm64) 42 | * x86_64-linux (linux-x64) 43 | 44 | ### Installing in a Rails Docker container 45 | 46 | You will need to install your extension(s) as part of the Docker build. In a typical Rails `Dockerfile` you could do this after copying the application code. For example: 47 | 48 | ``` diff 49 | # Install application gems 50 | COPY Gemfile Gemfile.lock vendor ./ 51 | RUN bundle install && \ 52 | rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git 53 | 54 | # Copy application code 55 | COPY . . 56 | 57 | + # Install extra sqlite packages 58 | + RUN bundle exec sqlpkg install asg017/ulid 59 | 60 | # Precompiling assets for production without requiring secret RAILS_MASTER_KEY 61 | RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile 62 | ``` 63 | 64 | ### Using a local installation of `sqlpkg` 65 | 66 | If you are not able to use the vendored standalone executables (for example, if you're on an unsupported platform), you can use a local installation of the `sqlpkg` executable by setting an environment variable named `SQLPKG_INSTALL_DIR` to the directory containing the executable. 67 | 68 | For example, if you've installed `sqlpkg` so that the executable is found at `/usr/local/bin/sqlpkg`, then you should set your environment variable like so: 69 | 70 | ``` sh 71 | SQLPKG_INSTALL_DIR=/usr/local/bin 72 | ``` 73 | 74 | This also works with relative paths. If you've installed into your app's directory at `./.bin/sqlpkg`: 75 | 76 | ``` sh 77 | SQLPKG_INSTALL_DIR=.bin 78 | ``` 79 | 80 | ## Usage 81 | 82 | ```shell 83 | bundle exec sqlpkg help 84 | ┌────────────────────────────────────────────────┐ 85 | │ sqlpkg is an SQLite package manager. │ 86 | │ Use it to install or update SQLite extensions. │ 87 | │ │ 88 | │ Commands: │ 89 | │ help Display help │ 90 | │ info Display package information │ 91 | │ init Init project scope │ 92 | │ install Install packages │ 93 | │ list List installed packages │ 94 | │ uninstall Uninstall package │ 95 | │ update Update installed packages │ 96 | │ version Display version │ 97 | │ which Display path to extension file │ 98 | └────────────────────────────────────────────────┘ 99 | ``` 100 | 101 | You can get the path to an installed extension using the `Sqlpkg.path_for` method, e.g.: 102 | 103 | ```ruby 104 | Sqlpkg.path_for("nalgeon/uuid") 105 | # => "./.sqlpkg/nalgeon/uuid/uuid.dylib" 106 | ``` 107 | 108 | You can also use the shorter `.[]` alias: 109 | 110 | ```ruby 111 | Sqlpkg["nalgeon/uuid"] 112 | # => "./.sqlpkg/nalgeon/uuid/uuid.dylib" 113 | ``` 114 | 115 | If you try to access an extension that hasn't been installed, a `Sqlpkg::ExtensionNotInstalledError` will be raised: 116 | 117 | ```ruby 118 | Sqlpkg["nalgeon/ulid"] 119 | # raises Sqlpkg::ExtensionNotInstalledError 120 | ``` 121 | 122 | This feature is particulary useful for the [new Rails feature](https://github.com/rails/rails/pull/53827) and [`sqlite3-ruby` feature](https://github.com/sparklemotion/sqlite3-ruby/pull/586) that allows automatically loading extensions via the `extensions` keyword defined in the Rails `config/database.yml` or the `SQLite3::Database.new` method call. You can now use either: 123 | 124 | ```yaml 125 | development: 126 | adapter: sqlite3 127 | extensions: 128 | - <%= Sqlpkg.path_for("asg017/ulid") %> 129 | ``` 130 | 131 | or if you are using `SQLite3::Database` directly: 132 | 133 | ```ruby 134 | db = SQLite3::Database.new(":memory:", extensions: [Sqlpkg.path_for("asg017/ulid")]) 135 | ``` 136 | 137 | ## Development 138 | 139 | After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. 140 | 141 | To install this gem onto your local machine, run `bundle exec rake install`. For maintainers, to release a new version, run `bin/release $VERSION`, which will create a git tag for the version, push git commits and tags, and push all of the platform-specific `.gem` files to [rubygems.org](https://rubygems.org). 142 | 143 | ## Contributing 144 | 145 | Bug reports and pull requests are welcome on GitHub at https://github.com/fractaledmind/sqlpkg-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/fractaledmind/sqlpkg-ruby/blob/main/CODE_OF_CONDUCT.md). 146 | 147 | ## License 148 | 149 | The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). 150 | 151 | ## Code of Conduct 152 | 153 | Everyone interacting in the Sqlpkg::Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fractaledmind/sqlpkg-ruby/blob/main/CODE_OF_CONDUCT.md). 154 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | sqlpkg (0.3.0) 5 | 6 | GEM 7 | remote: https://rubygems.org/ 8 | specs: 9 | actioncable (8.0.2) 10 | actionpack (= 8.0.2) 11 | activesupport (= 8.0.2) 12 | nio4r (~> 2.0) 13 | websocket-driver (>= 0.6.1) 14 | zeitwerk (~> 2.6) 15 | actionmailbox (8.0.2) 16 | actionpack (= 8.0.2) 17 | activejob (= 8.0.2) 18 | activerecord (= 8.0.2) 19 | activestorage (= 8.0.2) 20 | activesupport (= 8.0.2) 21 | mail (>= 2.8.0) 22 | actionmailer (8.0.2) 23 | actionpack (= 8.0.2) 24 | actionview (= 8.0.2) 25 | activejob (= 8.0.2) 26 | activesupport (= 8.0.2) 27 | mail (>= 2.8.0) 28 | rails-dom-testing (~> 2.2) 29 | actionpack (8.0.2) 30 | actionview (= 8.0.2) 31 | activesupport (= 8.0.2) 32 | nokogiri (>= 1.8.5) 33 | rack (>= 2.2.4) 34 | rack-session (>= 1.0.1) 35 | rack-test (>= 0.6.3) 36 | rails-dom-testing (~> 2.2) 37 | rails-html-sanitizer (~> 1.6) 38 | useragent (~> 0.16) 39 | actiontext (8.0.2) 40 | actionpack (= 8.0.2) 41 | activerecord (= 8.0.2) 42 | activestorage (= 8.0.2) 43 | activesupport (= 8.0.2) 44 | globalid (>= 0.6.0) 45 | nokogiri (>= 1.8.5) 46 | actionview (8.0.2) 47 | activesupport (= 8.0.2) 48 | builder (~> 3.1) 49 | erubi (~> 1.11) 50 | rails-dom-testing (~> 2.2) 51 | rails-html-sanitizer (~> 1.6) 52 | activejob (8.0.2) 53 | activesupport (= 8.0.2) 54 | globalid (>= 0.3.6) 55 | activemodel (8.0.2) 56 | activesupport (= 8.0.2) 57 | activerecord (8.0.2) 58 | activemodel (= 8.0.2) 59 | activesupport (= 8.0.2) 60 | timeout (>= 0.4.0) 61 | activestorage (8.0.2) 62 | actionpack (= 8.0.2) 63 | activejob (= 8.0.2) 64 | activerecord (= 8.0.2) 65 | activesupport (= 8.0.2) 66 | marcel (~> 1.0) 67 | activesupport (8.0.2) 68 | base64 69 | benchmark (>= 0.3) 70 | bigdecimal 71 | concurrent-ruby (~> 1.0, >= 1.3.1) 72 | connection_pool (>= 2.2.5) 73 | drb 74 | i18n (>= 1.6, < 2) 75 | logger (>= 1.4.2) 76 | minitest (>= 5.1) 77 | securerandom (>= 0.3) 78 | tzinfo (~> 2.0, >= 2.0.5) 79 | uri (>= 0.13.1) 80 | ast (2.4.3) 81 | base64 (0.3.0) 82 | benchmark (0.4.1) 83 | bigdecimal (3.2.1) 84 | builder (3.3.0) 85 | concurrent-ruby (1.3.5) 86 | connection_pool (2.5.3) 87 | crass (1.0.6) 88 | date (3.4.1) 89 | drb (2.2.3) 90 | erb (5.0.1) 91 | erubi (1.13.1) 92 | globalid (1.2.1) 93 | activesupport (>= 6.1) 94 | i18n (1.14.7) 95 | concurrent-ruby (~> 1.0) 96 | io-console (0.8.0) 97 | irb (1.15.2) 98 | pp (>= 0.6.0) 99 | rdoc (>= 4.0.0) 100 | reline (>= 0.4.2) 101 | json (2.12.2) 102 | language_server-protocol (3.17.0.5) 103 | lint_roller (1.1.0) 104 | logger (1.7.0) 105 | loofah (2.24.1) 106 | crass (~> 1.0.2) 107 | nokogiri (>= 1.12.0) 108 | mail (2.8.1) 109 | mini_mime (>= 0.1.1) 110 | net-imap 111 | net-pop 112 | net-smtp 113 | marcel (1.0.4) 114 | mini_mime (1.1.5) 115 | mini_portile2 (2.8.9) 116 | minitest (5.25.5) 117 | net-imap (0.5.8) 118 | date 119 | net-protocol 120 | net-pop (0.1.2) 121 | net-protocol 122 | net-protocol (0.2.2) 123 | timeout 124 | net-smtp (0.5.1) 125 | net-protocol 126 | nio4r (2.7.4) 127 | nokogiri (1.18.8) 128 | mini_portile2 (~> 2.8.2) 129 | racc (~> 1.4) 130 | nokogiri (1.18.8-arm64-darwin) 131 | racc (~> 1.4) 132 | nokogiri (1.18.8-x86_64-linux-gnu) 133 | racc (~> 1.4) 134 | parallel (1.27.0) 135 | parser (3.3.8.0) 136 | ast (~> 2.4.1) 137 | racc 138 | pp (0.6.2) 139 | prettyprint 140 | prettyprint (0.2.0) 141 | prism (1.4.0) 142 | psych (5.2.6) 143 | date 144 | stringio 145 | racc (1.8.1) 146 | rack (3.1.15) 147 | rack-session (2.1.1) 148 | base64 (>= 0.1.0) 149 | rack (>= 3.0.0) 150 | rack-test (2.2.0) 151 | rack (>= 1.3) 152 | rackup (2.2.1) 153 | rack (>= 3) 154 | rails (8.0.2) 155 | actioncable (= 8.0.2) 156 | actionmailbox (= 8.0.2) 157 | actionmailer (= 8.0.2) 158 | actionpack (= 8.0.2) 159 | actiontext (= 8.0.2) 160 | actionview (= 8.0.2) 161 | activejob (= 8.0.2) 162 | activemodel (= 8.0.2) 163 | activerecord (= 8.0.2) 164 | activestorage (= 8.0.2) 165 | activesupport (= 8.0.2) 166 | bundler (>= 1.15.0) 167 | railties (= 8.0.2) 168 | rails-dom-testing (2.3.0) 169 | activesupport (>= 5.0.0) 170 | minitest 171 | nokogiri (>= 1.6) 172 | rails-html-sanitizer (1.6.2) 173 | loofah (~> 2.21) 174 | nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) 175 | railties (8.0.2) 176 | actionpack (= 8.0.2) 177 | activesupport (= 8.0.2) 178 | irb (~> 1.13) 179 | rackup (>= 1.0.0) 180 | rake (>= 12.2) 181 | thor (~> 1.0, >= 1.2.2) 182 | zeitwerk (~> 2.6) 183 | rainbow (3.1.1) 184 | rake (13.3.0) 185 | rdoc (6.14.0) 186 | erb 187 | psych (>= 4.0.0) 188 | regexp_parser (2.10.0) 189 | reline (0.6.1) 190 | io-console (~> 0.5) 191 | rubocop (1.75.8) 192 | json (~> 2.3) 193 | language_server-protocol (~> 3.17.0.2) 194 | lint_roller (~> 1.1.0) 195 | parallel (~> 1.10) 196 | parser (>= 3.3.0.2) 197 | rainbow (>= 2.2.2, < 4.0) 198 | regexp_parser (>= 2.9.3, < 3.0) 199 | rubocop-ast (>= 1.44.0, < 2.0) 200 | ruby-progressbar (~> 1.7) 201 | unicode-display_width (>= 2.4.0, < 4.0) 202 | rubocop-ast (1.45.0) 203 | parser (>= 3.3.7.2) 204 | prism (~> 1.4) 205 | rubocop-performance (1.25.0) 206 | lint_roller (~> 1.1) 207 | rubocop (>= 1.75.0, < 2.0) 208 | rubocop-ast (>= 1.38.0, < 2.0) 209 | ruby-progressbar (1.13.0) 210 | rubyzip (2.4.1) 211 | securerandom (0.4.1) 212 | sqlite3 (2.6.0) 213 | mini_portile2 (~> 2.8.0) 214 | sqlite3 (2.6.0-arm64-darwin) 215 | sqlite3 (2.6.0-x86_64-linux-gnu) 216 | standard (1.50.0) 217 | language_server-protocol (~> 3.17.0.2) 218 | lint_roller (~> 1.0) 219 | rubocop (~> 1.75.5) 220 | standard-custom (~> 1.0.0) 221 | standard-performance (~> 1.8) 222 | standard-custom (1.0.2) 223 | lint_roller (~> 1.0) 224 | rubocop (~> 1.50) 225 | standard-performance (1.8.0) 226 | lint_roller (~> 1.1) 227 | rubocop-performance (~> 1.25.0) 228 | stringio (3.1.7) 229 | thor (1.3.2) 230 | timeout (0.4.3) 231 | tzinfo (2.0.6) 232 | concurrent-ruby (~> 1.0) 233 | unicode-display_width (3.1.4) 234 | unicode-emoji (~> 4.0, >= 4.0.4) 235 | unicode-emoji (4.0.4) 236 | uri (1.0.3) 237 | useragent (0.16.11) 238 | websocket-driver (0.8.0) 239 | base64 240 | websocket-extensions (>= 0.1.0) 241 | websocket-extensions (0.1.5) 242 | zeitwerk (2.7.3) 243 | 244 | PLATFORMS 245 | arm64-darwin-21 246 | ruby 247 | x86_64-linux 248 | 249 | DEPENDENCIES 250 | minitest (~> 5.16) 251 | rails 252 | rake (~> 13.0) 253 | rubyzip 254 | sqlite3 255 | sqlpkg! 256 | standard (~> 1.3) 257 | 258 | BUNDLED WITH 259 | 2.6.9 260 | --------------------------------------------------------------------------------