diff --git a/.github/workflows/native-unix.yml b/.github/workflows/native-unix.yml index 05130d3930..95160e655a 100644 --- a/.github/workflows/native-unix.yml +++ b/.github/workflows/native-unix.yml @@ -366,8 +366,14 @@ jobs: cd tar xvf ~/local.tgz + - name: Install lgi (Lua GObject Introspection) + run: | + env PKG_CONFIG_PATH="${CONDA_PREFIX}/lib/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}" \ + luarocks install lgi + - name: Build GLib Driver Manager run: | + eval "$(luarocks path)" env BUILD_ALL=0 BUILD_DRIVER_MANAGER=1 ./ci/scripts/glib_build.sh "$(pwd)" "$(pwd)/build" "$HOME/local" - name: Test GLib/Ruby Driver Manager run: | diff --git a/ci/conda_env_glib.txt b/ci/conda_env_glib.txt index 9b2944ad45..3c4ca646fd 100644 --- a/ci/conda_env_glib.txt +++ b/ci/conda_env_glib.txt @@ -18,6 +18,8 @@ arrow-c-glib glib gobject-introspection +luajit +luarocks meson postgresql ruby diff --git a/ci/scripts/glib_build.sh b/ci/scripts/glib_build.sh index 64255d8dd5..2ecd178238 100755 --- a/ci/scripts/glib_build.sh +++ b/ci/scripts/glib_build.sh @@ -63,6 +63,19 @@ build_subproject() { if [[ "${enable_vapi}" = "true" ]]; then "${build_dir}/glib/example/vala/sqlite" fi + if type luajit > /dev/null 2>&1; then + local gi_typelib_path="${build_dir}/glib/adbc-glib" + gi_typelib_path="${gi_typelib_path}:${build_dir}/glib/adbc-arrow-glib" + gi_typelib_path="${gi_typelib_path}:${install_dir}/lib/girepository-1.0" + if [[ -n "${CONDA_PREFIX}" ]]; then + gi_typelib_path="${gi_typelib_path}:${CONDA_PREFIX}/lib/girepository-1.0" + fi + if [[ -n "${GI_TYPELIB_PATH}" ]]; then + gi_typelib_path="${gi_typelib_path}:${GI_TYPELIB_PATH}" + fi + GI_TYPELIB_PATH="${gi_typelib_path}" \ + luajit "${source_dir}/glib/example/lua/sqlite.lua" + fi } main() { diff --git a/glib/example/README.md b/glib/example/README.md index feb18efea5..27bd398fd2 100644 --- a/glib/example/README.md +++ b/glib/example/README.md @@ -24,6 +24,7 @@ There are example codes in this directory. C example codes exist in this directory. Language bindings example codes exists in sub directories: + * `lua/`: Lua examples * `vala/`: Vala examples ## C example codes diff --git a/glib/example/lua/README.md b/glib/example/lua/README.md new file mode 100644 index 0000000000..5616ea3e95 --- /dev/null +++ b/glib/example/lua/README.md @@ -0,0 +1,46 @@ + + +# ADBC GLib Lua example + +There are Lua example codes in this directory. + +The Lua examples use [LGI](https://github.com/lgi-devs/lgi) (Lua +GObject Introspection) to access the ADBC GLib bindings via +GObject Introspection. + +## How to run + +You need to install LGI and the ADBC GLib bindings. The GObject +Introspection typelibs for ADBC GLib (`ADBC-1.0.typelib` and +`ADBCArrow-1.0.typelib`) and Arrow GLib (`Arrow-*.typelib`) must be +findable. If they aren't installed to a standard location, set +`GI_TYPELIB_PATH`. + +Here is a command line to run an example in this directory: + +```console +$ lua XXX.lua +``` + +## Lua example codes + +Here are example codes in this directory: + + * `sqlite.lua`: It shows how to connect to a SQLite database. diff --git a/glib/example/lua/meson.build b/glib/example/lua/meson.build new file mode 100644 index 0000000000..129ea922fa --- /dev/null +++ b/glib/example/lua/meson.build @@ -0,0 +1,24 @@ +# -*- indent-tabs-mode: nil -*- +# +# 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. + +files = ['README.md', 'sqlite.lua'] +install_data( + files, + install_dir: join_paths(data_dir, 'adbc-arrow-glib', 'example', 'lua'), +) diff --git a/glib/example/lua/sqlite.lua b/glib/example/lua/sqlite.lua new file mode 100644 index 0000000000..104d45ca2f --- /dev/null +++ b/glib/example/lua/sqlite.lua @@ -0,0 +1,55 @@ +-- 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. + +local lgi = require("lgi") +local GADBC = lgi.ADBC +local GADBCArrow = lgi.ADBCArrow + +local database = GADBC.Database.new() +local success, err = database:set_option("driver", "adbc_driver_sqlite") +if not success then + error("Failed to set driver: " .. err.message) +end +success, err = database:set_option("uri", ":memory:") +if not success then + error("Failed to set database URI: " .. err.message) +end +success, err = database:init() +if not success then + error("Failed to create a database: " .. err.message) +end + +local connection = GADBC.Connection.new() +success, err = connection:init(database) +if not success then + error("Failed to create a connection: " .. err.message) +end + +local statement = GADBCArrow.Statement.new(connection) +local sql = "SELECT sqlite_version() AS version" +success, err = statement:set_sql_query(sql) +if not success then + error("Failed to set a query: " .. err.message) +end + +local reader, err_or_n_rows_affected = statement:execute(true) +if not reader then + error("Failed to execute a statement: " .. err_or_n_rows_affected.message) +end + +local result_table = reader:read_all() +io.write(string.format("Result:\n%s", result_table:to_string())) diff --git a/glib/example/meson.build b/glib/example/meson.build index df691dd320..8696b142c5 100644 --- a/glib/example/meson.build +++ b/glib/example/meson.build @@ -33,4 +33,5 @@ install_data( install_dir: join_paths(data_dir, meson.project_name(), 'example'), ) +subdir('lua') subdir('vala')