Skip to content

sbrunk/duckdb.mojo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

duckdb.mojo

Mojo bindings for DuckDB.

Status:

  • Work in progress, many parts of the API are still missing (PRs welcome).

Example

from duckdb import *

var con = DuckDB.connect(":memory:")

_ = con.execute(
    """
CREATE TABLE train_services AS
FROM 's3://duckdb-blobs/train_services.parquet';
"""
)

var result = con.execute(
    """
-- Get the top-3 busiest train stations
SELECT station_name, count(*) AS num_services
FROM train_services
GROUP BY ALL
ORDER BY num_services DESC
LIMIT 3;
"""
).fetch_all()

for col in result.columns():
    print(col[])

print()

for row in range(len(result)):
    print(
        result.get(varchar, col=0, row=row).value(),
        " ",
        result.get(bigint, col=1, row=row).value(),
    )

Installation

  1. Install Mojo. Currently nightly >= 2024.7.1105 is required, so install or update the nightly version: modular install nightly/mojo
  2. Download the DuckDB C/C++ library from the installation page.
  3. Extract libduckdb.so (Linux) or libduckdb.dylib (macOS) to the project directory.
  4. Set library path:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$(realpath .) # Linux
export DYLD_FALLBACK_LIBRARY_PATH=$(realpath .) # macOS
  1. Run
mojo example.mojo

Run Tests

mojo test -I .

About

Mojo Bindings for DuckDB

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published