prql-rb 0.1.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.
@@ -0,0 +1,15 @@
1
+ [package]
2
+ name = "prql_rb"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ publish = false
6
+
7
+ [lib]
8
+ crate-type = ["cdylib"]
9
+
10
+ [dependencies]
11
+ magnus = "0.8"
12
+ prqlc = { version = "0.13.14", default-features = false }
13
+
14
+ [profile.release.package.prqlc]
15
+ strip = "debuginfo"
@@ -0,0 +1,4 @@
1
+ require "mkmf"
2
+ require "rb_sys/mkmf"
3
+
4
+ create_rust_makefile("prql_rb/prql_rb")
@@ -0,0 +1,38 @@
1
+ use std::str::FromStr;
2
+
3
+ use magnus::{function, prelude::*, Error, Ruby};
4
+ use prqlc::{Options, Target};
5
+
6
+ fn compile(
7
+ ruby: &Ruby,
8
+ source: String,
9
+ target: String,
10
+ format: bool,
11
+ signature_comment: bool,
12
+ ) -> Result<String, Error> {
13
+ let compile_error = ruby
14
+ .define_module("PrqlRb")?
15
+ .const_get::<_, magnus::exception::ExceptionClass>("CompileError")?;
16
+ let target =
17
+ Target::from_str(&target).map_err(|error| Error::new(compile_error, error.to_string()))?;
18
+ let options = Options::default()
19
+ .with_target(target)
20
+ .with_format(format)
21
+ .with_signature_comment(signature_comment);
22
+
23
+ prqlc::compile(&source, &options)
24
+ .map_err(|errors| Error::new(compile_error, errors.to_string()))
25
+ }
26
+
27
+ fn compiler_version() -> String {
28
+ prqlc::compiler_version().to_string()
29
+ }
30
+
31
+ #[magnus::init]
32
+ fn init(ruby: &Ruby) -> Result<(), Error> {
33
+ let module = ruby.define_module("PrqlRb")?;
34
+ module.define_error("CompileError", ruby.exception_standard_error())?;
35
+ module.define_module_function("native_compile", function!(compile, 4))?;
36
+ module.define_module_function("compiler_version", function!(compiler_version, 0))?;
37
+ Ok(())
38
+ }
data/lib/prql-rb.rb ADDED
@@ -0,0 +1,3 @@
1
+ # Entry point matching the gem name (prql-rb). Bundler auto-requires
2
+ # the gem name, so this shim forwards to the real module definition.
3
+ require_relative "prql_rb"
@@ -0,0 +1,3 @@
1
+ module PrqlRb
2
+ VERSION = "0.1.0"
3
+ end
data/lib/prql_rb.rb ADDED
@@ -0,0 +1,19 @@
1
+ require_relative "prql_rb/version"
2
+
3
+ # Try the versioned extension first (precompiled fat gems ship
4
+ # lib/prql_rb/<ruby-version>/prql_rb.so), then fall back to a
5
+ # source-built extension at lib/prql_rb/prql_rb.so.
6
+ begin
7
+ RUBY_VERSION =~ /(\d+\.\d+)/
8
+ require_relative "prql_rb/#{Regexp.last_match(1)}/prql_rb"
9
+ rescue LoadError
10
+ require_relative "prql_rb/prql_rb"
11
+ end
12
+
13
+ module PrqlRb
14
+ DEFAULT_TARGET = "sql.postgres"
15
+
16
+ def self.compile(source, target: DEFAULT_TARGET, format: true, signature_comment: false)
17
+ native_compile(source, target, format, signature_comment)
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prql-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mendel Kramer
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rb_sys
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '0.9'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '0.9'
26
+ description: Ruby bindings for the PRQL compiler (prqlc), a Rust implementation of
27
+ the PRQL pipelined query language.
28
+ executables: []
29
+ extensions:
30
+ - ext/prql_rb/extconf.rb
31
+ extra_rdoc_files: []
32
+ files:
33
+ - LICENSE
34
+ - README.md
35
+ - bin/compile
36
+ - bin/setup
37
+ - ext/prql_rb/Cargo.lock
38
+ - ext/prql_rb/Cargo.toml
39
+ - ext/prql_rb/extconf.rb
40
+ - ext/prql_rb/src/lib.rs
41
+ - lib/prql-rb.rb
42
+ - lib/prql_rb.rb
43
+ - lib/prql_rb/version.rb
44
+ homepage: https://github.com/mendelk/prql-rb
45
+ licenses:
46
+ - AGPL-3.0-or-later
47
+ metadata:
48
+ homepage_uri: https://github.com/mendelk/prql-rb
49
+ source_code_uri: https://github.com/mendelk/prql-rb
50
+ changelog_uri: https://github.com/mendelk/prql-rb/releases
51
+ rubygems_mfa_required: 'true'
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '3.2'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 3.6.9
67
+ specification_version: 4
68
+ summary: Compile PRQL to SQL using prqlc
69
+ test_files: []