This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git


The following commit(s) were added to refs/heads/main by this push:
     new ed58536a5 feat!(ruby): set LoadFlags::DEFAULT on Database.new and 
allow override in open (#4402)
ed58536a5 is described below

commit ed58536a553e0be3d03e67612b431dba9692d88f
Author: Bryce Mecum <[email protected]>
AuthorDate: Tue Jun 16 15:52:13 2026 -0700

    feat!(ruby): set LoadFlags::DEFAULT on Database.new and allow override in 
open (#4402)
    
    The current way to load an ADBC driver installed via ADBC driver
    manifest is cumbersome because the user has to do it over multiple calls
    and can't use the block-based `Database.open` if they need to customize
    init. This is currently what it looks like to load the sqlite driver
    installed via manfiest:
    
    ```ruby
    database = ADBC::Database.new
    
    begin
      database.set_option("driver", "sqlite")
      database.set_option("uri", "games.sqlite")
      database.set_load_flags(ADBC::LoadFlags::DEFAULT)
    ...
    ```
    
    It would be better if we could write:
    
    ```ruby
    ADBC::Database.open(driver: "sqlite", uri: "games.sqlite") do |database|
      ...
    end
    ```
    
    This PR does two things,
    
    1. Set the default value of LoadFlags to ADBC_LOAD_FLAG_DEFAULT. This
    matches Python.
    2. Adds a load_flags keyword arg to Database.open so the user can
    override it without having to drop down to Database.new
    
    This is a breaking change because existing direct and indirect callers
    of Database.new will get different driver loading behavior.
    
    ---------
    
    Co-authored-by: Sutou Kouhei <[email protected]>
---
 glib/adbc-glib/database.c  |  6 +++++
 glib/adbc-glib/database.h  |  2 +-
 ruby/lib/adbc/database.rb  |  3 ++-
 ruby/test/test-database.rb | 63 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 72 insertions(+), 2 deletions(-)

diff --git a/glib/adbc-glib/database.c b/glib/adbc-glib/database.c
index 886b3474b..0c86443d0 100644
--- a/glib/adbc-glib/database.c
+++ b/glib/adbc-glib/database.c
@@ -75,6 +75,12 @@ GADBCDatabase* gadbc_database_new(GError** error) {
   AdbcStatusCode status_code = AdbcDatabaseNew(&(priv->adbc_database), 
&adbc_error);
   priv->initialized =
       gadbc_error_check(error, status_code, &adbc_error, 
"[adbc][database][new]");
+  if (priv->initialized) {
+    status_code = AdbcDriverManagerDatabaseSetLoadFlags(
+        &(priv->adbc_database), GADBC_LOAD_FLAGS_DEFAULT, &adbc_error);
+    priv->initialized = gadbc_error_check(error, status_code, &adbc_error,
+                                          "[adbc][database][set-load-flags]");
+  }
   if (!priv->initialized) {
     g_object_unref(database);
     return NULL;
diff --git a/glib/adbc-glib/database.h b/glib/adbc-glib/database.h
index 5f510b346..1c0464987 100644
--- a/glib/adbc-glib/database.h
+++ b/glib/adbc-glib/database.h
@@ -48,7 +48,7 @@ typedef enum {
 } GADBCLoadFlags;
 
 /**
- * GADBC_LOAD_FLAGAS_DEFAULT:
+ * GADBC_LOAD_FLAGS_DEFAULT:
  *
  * The default GADBCLoadFlags.
  *
diff --git a/ruby/lib/adbc/database.rb b/ruby/lib/adbc/database.rb
index 15e6abfbc..60e715d55 100644
--- a/ruby/lib/adbc/database.rb
+++ b/ruby/lib/adbc/database.rb
@@ -18,13 +18,14 @@
 module ADBC
   class Database
     class << self
-      def open(**options)
+      def open(load_flags: nil, **options)
         database = new
         need_release = true
         begin
           options.each do |key, value|
             database.set_option(key, value)
           end
+          database.set_load_flags(load_flags) unless load_flags.nil?
           database.init
           if block_given?
             yield(database)
diff --git a/ruby/test/test-database.rb b/ruby/test/test-database.rb
new file mode 100644
index 000000000..19d9ad009
--- /dev/null
+++ b/ruby/test/test-database.rb
@@ -0,0 +1,63 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+class DatabaseTest < Test::Unit::TestCase
+  sub_test_case(".open") do
+    sub_test_case("manifest") do
+      def setup
+        Dir.mktmpdir do |tmpdir|
+          File.write(File.join(tmpdir, "testdriver.toml"), <<~TOML)
+            name = "test driver"
+            version = "0.1.0"
+
+            [Driver]
+            shared = "adbc_driver_sqlite"
+          TOML
+          driver_path, ENV["ADBC_DRIVER_PATH"] = ENV["ADBC_DRIVER_PATH"], 
tmpdir
+          begin
+            yield
+          ensure
+            ENV["ADBC_DRIVER_PATH"] = driver_path
+          end
+        end
+      end
+
+      def test_search_env_finds_driver
+        ADBC::Database.open(driver: "testdriver",
+                            uri: ":memory:",
+                            load_flags: :search_env) do |database|
+          database.connect do |connection|
+              assert_equal([
+                              Arrow::Table.new("1" => 
Arrow::Int64Array.new([1])),
+                              -1,
+                           ],
+                           connection.query("SELECT 1"))
+          end
+        end
+      end
+
+      def test_no_flags_cannot_find_driver
+        assert_raise(ADBC::Error::NotFound) do
+          ADBC::Database.open(driver: "testdriver",
+                              uri: ":memory:",
+                              load_flags: 0) do |_database|
+          end
+        end
+      end
+    end
+  end
+end

Reply via email to