sqlpkg 0.2.3.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78bb33046cc04d98264ccaaa0c18faeeeda57be75ec72124da77f72a4a7cfa1d
4
- data.tar.gz: aff9b55b8734492e8d65af130d12ef0f90fe79d17994e670aaa257b0616b1435
3
+ metadata.gz: 3131c063c4d2bc767ff4f1d56ff992fbdd4fd2d9f0bcb114a231fee8f1558df8
4
+ data.tar.gz: 1ea975cc4eff3301c4d908d7832dc93ef4ad85185ddfec919a78b4d3ef9966b7
5
5
  SHA512:
6
- metadata.gz: 9aed7b9656ca5a5b8983ad19f49aeb50d657df7b91a80dcdef49216768aaf9c937aa6dbe9655a721f39bc5de0d3f8af5cca8eb2d19a64bb4e1f6d97f01e1f731
7
- data.tar.gz: c66e09ea0ad120f75f5f12f1ddcf12b0e7dec06b959ab42ef07789930005c039878ade6f3bf54808b1b3e682130e12546069651115c8e59a8e21c7dfc1665310
6
+ metadata.gz: 914dca28b67247c8577c7286d07ccd44aa9ea4bc89311b26056955f67d6dd42cd30f8f3770b873f0667a1f0f9a6a026ec2c2175a33216d225e0eeeb4ee602df3
7
+ data.tar.gz: 8dc094a3227f069c312e4e8ca7e9a3761b2b68ed13c421a3255dd0e39f35c8fdf6f600b816d71cb08f764a64a3b34e6920dbb80f8a652121a0063075a06043e0
data/README.md CHANGED
@@ -5,16 +5,19 @@
5
5
  ## Installation
6
6
 
7
7
  Install the gem and add to the application's Gemfile by executing:
8
-
9
- $ bundle add sqlpkg
8
+ ```shell
9
+ bundle add sqlpkg
10
+ ```
10
11
 
11
12
  If bundler is not being used to manage dependencies, install the gem by executing:
12
-
13
- $ gem install sqlpkg
13
+ ```shell
14
+ gem install sqlpkg
15
+ ```
14
16
 
15
17
  After installing the gem, run the installer:
16
-
17
- $ rails generate sqlpkg:install
18
+ ```shell
19
+ rails generate sqlpkg:install
20
+ ```
18
21
 
19
22
  The installer does three things:
20
23
 
@@ -23,8 +26,9 @@ The installer does three things:
23
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
24
27
 
25
28
  Once properly integrated into your Rails application, you can install any extension listed on [the `sqlpkg` registry](https://sqlpkg.org/all/) by executing:
26
-
27
- $ bundle exec sqlpkg install PACKAGE_IDENTIFIER
29
+ ```shell
30
+ bundle exec sqlpkg install PACKAGE_IDENTIFIER
31
+ ```
28
32
 
29
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.
30
34
 
@@ -56,7 +60,7 @@ SQLPKG_INSTALL_DIR=.bin
56
60
  ## Usage
57
61
 
58
62
  ```shell
59
- $ bundle exec sqlpkg help
63
+ bundle exec sqlpkg help
60
64
  ┌────────────────────────────────────────────────┐
61
65
  │ sqlpkg is an SQLite package manager. │
62
66
  │ Use it to install or update SQLite extensions. │
@@ -74,6 +78,42 @@ $ bundle exec sqlpkg help
74
78
  └────────────────────────────────────────────────┘
75
79
  ```
76
80
 
81
+ You can get the path to an installed extension using the `Sqlpkg.path_for` method, e.g.:
82
+
83
+ ```ruby
84
+ Sqlpkg.path_for("nalgeon/uuid")
85
+ # => "./.sqlpkg/nalgeon/uuid/uuid.dylib"
86
+ ```
87
+
88
+ You can also use the shorter `.[]` alias:
89
+
90
+ ```ruby
91
+ Sqlpkg["nalgeon/uuid"]
92
+ # => "./.sqlpkg/nalgeon/uuid/uuid.dylib"
93
+ ```
94
+
95
+ If you try to access an extension that hasn't been installed, a `Sqlpkg::ExtensionNotInstalledError` will be raised:
96
+
97
+ ```ruby
98
+ Sqlpkg["nalgeon/ulid"]
99
+ # raises Sqlpkg::ExtensionNotInstalledError
100
+ ```
101
+
102
+ 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:
103
+
104
+ ```yaml
105
+ development:
106
+ adapter: sqlite3
107
+ extensions:
108
+ - <%= Sqlpkg.path_for("asg017/ulid") %>
109
+ ```
110
+
111
+ or if you are using `SQLite3::Database` directly:
112
+
113
+ ```ruby
114
+ db = SQLite3::Database.new(":memory:", extensions: [Sqlpkg.path_for("asg017/ulid")])
115
+ ```
116
+
77
117
  ## Development
78
118
 
79
119
  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.
@@ -11,6 +11,13 @@ module Sqlpkg
11
11
  empty_directory ".sqlpkg"
12
12
  end
13
13
 
14
+ def create_gitignore_in_sqlpkg_project_scope_directory
15
+ create_file ".sqlpkg/.gitignore", <<~CONTENT
16
+ *
17
+ !.gitignore
18
+ CONTENT
19
+ end
20
+
14
21
  def create_empty_sqlpkg_lockfile
15
22
  create_file "sqlpkg.lock", <<~CONTENT
16
23
  {
@@ -1,7 +1,7 @@
1
1
  module Sqlpkg
2
- # constants describing the upstream tailwindcss project
2
+ # constants describing the upstream sqlpkg-cli project
3
3
  module Upstream
4
- VERSION = "0.2.3"
4
+ VERSION = "0.3.0"
5
5
 
6
6
  # rubygems platform name => upstream release filename
7
7
  NATIVE_PLATFORMS = {
@@ -1,3 +1,3 @@
1
1
  module Sqlpkg
2
- VERSION = "0.2.3.1"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/sqlpkg.rb CHANGED
@@ -1,6 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
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
4
37
  end
5
38
 
6
39
  require_relative "sqlpkg/version"
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqlpkg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Margheim
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-05-05 00:00:00.000000000 Z
10
+ date: 2025-06-03 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rubyzip
@@ -52,7 +51,6 @@ dependencies:
52
51
  - - ">="
53
52
  - !ruby/object:Gem::Version
54
53
  version: '0'
55
- description:
56
54
  email:
57
55
  - stephen.margheim@gmail.com
58
56
  executables:
@@ -79,7 +77,6 @@ metadata:
79
77
  rubygems_mfa_required: 'true'
80
78
  source_code_uri: https://github.com/fractaledmind/sqlpkg-ruby
81
79
  changelog_uri: https://github.com/fractaledmind/sqlpkg-ruby/CHANGELOG.md
82
- post_install_message:
83
80
  rdoc_options: []
84
81
  require_paths:
85
82
  - lib
@@ -94,8 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
91
  - !ruby/object:Gem::Version
95
92
  version: '0'
96
93
  requirements: []
97
- rubygems_version: 3.5.1
98
- signing_key:
94
+ rubygems_version: 3.6.3
99
95
  specification_version: 4
100
96
  summary: Integrate sqlpkg with the RubyGems infrastructure.
101
97
  test_files: []