Giter Site home page Giter Site logo

sqlite-toml-vtab's Introduction

SQlite TOML Virtual Table

A SQLite extension exposing TOML files as a virtual table.

WARNING: This extension is a toy project and you should not expect any active maintenance. It depends on sqlite-loadable-rs which is unstable.

Using the feature rlib the extension can be used as a rust lib, loadable using rusqlite.

Getting started

The examples below assume a set of TOML files containing a recipe each with a shape such as:

name = "Yorkshire pudding"
preparation_time = "10 min"
cooking_time = "30 min"
servings = 12
instructions = """
(…)
"""
ingredients = [
  { name = "egg",    quantity = 3                      },
  { name = "milk",   quantity = 1, unit = "cup"        },
  { name = "flour",  quantity = 1, unit = "cup"        },
  { name = "butter", quantity = 2, unit = "tablespoon" },
]

Load the extension

Assuming the compiled name is toml_vtab:

.load ./dist/toml_vtab

Initialise a virtual table

CREATE VIRTUAL TABLE temp.recipe USING toml(dirname="recipes");

The above will create a new table recipe within the temp schema with two columns filename and value where the latter will have the full contents of the TOML file as a JSON string.

Querying the data

Say you want to list all ingredient names out of all the recipes:

SELECT DISTINCT
    json_extract(ingredient.value, '$.name') AS ingredient_name
FROM
    recipe, json_each(json_extract(recipe.value, '$.ingredients')) AS ingredient
ORDER BY ingredient_name

## Check the extension version

```sql
SELECT toml_version();


## Licence

Arnau Siches under the [MIT License](./LICENCE)

sqlite-toml-vtab's People

Contributors

arnau avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.