Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions glib/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions glib/example/lua/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!---
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.
-->

# 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.
24 changes: 24 additions & 0 deletions glib/example/lua/meson.build
Original file line number Diff line number Diff line change
@@ -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'),
)
55 changes: 55 additions & 0 deletions glib/example/lua/sqlite.lua
Original file line number Diff line number Diff line change
@@ -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()))
1 change: 1 addition & 0 deletions glib/example/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ install_data(
install_dir: join_paths(data_dir, meson.project_name(), 'example'),
)

subdir('lua')
subdir('vala')
Loading