Giter VIP home page Giter VIP logo

libshsqlite's Introduction

libshsqlite

A SQLite extension which loads data from Soracom Harvest Data as a virtual table.

Tested Platform

  • SQLite 3.40.0
  • Rust 1.65.0 (stable-aarch64-apple-darwin)
  • macOS 12.6 (Monterey) on Apple M1 MAX
  • SORACOM Harvest (English/Japanese)

Getting Started

Clone the Repository

$ git clone github.com/0x6b/libshsqlite
$ cd libshsqlite

Setup and Soracom Harvest Data

  1. Sign-up SORACOM to get a (virtual) SIM (English/Japanese)
  2. Enable Soracom Harvest Data (English/Japanese)
  3. Create a SAM user with following permission:
    {
      "statements": [
        {
          "api": [
            "Sim:getDataFromSim",
            "Subscriber:getDataFromSubscriber",
            "DataEntry:getDataEntries",
            "DataEntry:getDataEntry"
          ],
          "effect": "allow"
        }
      ]
    }
  4. Generate and authentication information for the user and save it for future reference

Send Some Data

See documentation (English/Japanese) for detail, or use deadly simple client in this repository (soracom_harvest_client), from your SIM or virtual SIM connected machine as follows:

$ cargo run -p soracom_harvest_client -- --udp hey # Say hello, via UDP

Build the Extension

$ cargo build --release

Load the Extension

  1. Export required environment variables with the credential:
    $ export LIBSHSQLITE_AUTH_KEY_ID=keyId-.. # authKeyId
    $ export LIBSHSQLITE_AUTH_KEY_SECRET=secret-... # authKey
  2. Launch SQLite:
    $ sqlite3
  3. Load the extension (you have to use "shsqlite" on Windows):
    .load target/release/libshsqlite
    If you get Error: unknown command or invalid arguments: "load". Enter ".help" for help , your SQLite is not capable for loading an extension. For macOS, install it with brew install sqlite3, and use it.

Query Your Data

  1. Create a virtual table for your Soracom Harvest Data by providing IMSI (IMSI of target SIM) as module argument. See reference below for available arguments other than IMSI:
    CREATE VIRTUAL TABLE harvest_data USING shsqlite(IMSI 'imsi-of-your-sim', COVERAGE 'japan');
  2. Run queries as usual:
    SELECT * FROM harvest_data;
    SELECT * FROM harvest_data WHERE value ->>'$.temperature' > 10;

Module Arguments Reference

Argument Description Default Required
IMSI Your IMSI None x
FROM Start time for the data entries search range (unix time in milliseconds). 1 days ago from now
TO End time for the data entries search range (unix time in milliseconds). now
COVERAGE Your SIM's coverage (global or japan) global
LIMIT Maximum number of data entries to retrieve. Should be between 1 and 1000. 100
CREATE VIRTUAL TABLE harvest_data USING shsqlite(
    IMSI '...',
    FROM '...',
    TO '...',
    COVERAGE 'japan|global',
    LIMIT '...'
);

Contributing

Please read CONTRIBUTING for more detail.

Acknowledgements

An article, Extending SQLite with Rust to support Excel files as virtual tables | Sergey Khabibullin , and its companion repository x2bool/xlite, for great write up and inspiration.

Limitations

  • The extension will load the data only once while creating a virtual table. If you want to pick up recent data, drop the table and create it again. Dropping the table won't erase your data on Soracom Harvest.
  • INSERT, UPDATE and DELETE statements won't be implemented.

Privacy

The extension never send your data to any server.

License

This extension is released under the MIT License. See LICENSE for details.

libshsqlite's People

Contributors

0x6b avatar

Stargazers

 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.