Git Product home page Git Product logo

cozodb-lisp's Introduction

Lisp Cozodb

About Cozodb

This is a Lisp wrapper for embedding Cozodb.

Cozodb is a really nice database with some interesting features:

  • Graph traversals
  • Vector search
  • Whole graph algorithms
  • Time travelling
  • Deduplication
  • Full-text search
  • Hi performance (up to 100K QPS)
  • Transactions

Cozodb is based upon Datalog and is really easy to do pretty advanced logic with some easy queries. Syntax is really nice, readable and more powerfull than SQL - as far as I can see :)

Documentation on usage is here.

Lisp api

Installation

(ql:quickload "cozodb")

First you need the binary file. You can get it two ways:

  • Download Cozodb and follow instructions for building
  • Or you can use the Linux version which is in the library folder in this project. If you have a Mac/Windows feel free to compile and make a pull request.

Make sure the .so file is in your path. Easy way on Linux is to do a export LD_LIBRARY_PATH=/path_to_dir_with_so_file in the same whell you start lisp job from (or put it in your .bashrc for example)

Usage

First move to the package

(in-package cozodb)

Then open a database with:

(open-db "/tmp/mydir")

This returns a integer which will be needed when doing a query. Query can be done two ways:

  1. Raw query. Following line creates a table and load it with two rows
(run-query db-id "?[l1, l2] <- [['a', 1], ['b',2]] :create stored {l1, l2}")
  1. Interpolated query. The same query, but with interpolation. The percentage sign is the interpolation char.
(query db-id "?[l1, l2] <- % :create stored {l1, l2}" '(("a" 1) ("b" 2))

To query the data in the newly created table we can du this:

(run-query db-id "?[a, b] := *stored[a, b]")

The results of the query is in json format.

To close database:

(close-db db-id)

There are two optional params when doing a query. They are extra-params and immutable. Have a look in the Cozodb for an exlpanation of these if you need them.

Running examples are in the test.lisp file

Backup and restore

(backup db-id "filename")
(restore db-id "filename")

See in the test-file for example on how to backup/restore.

Viewing queries in a tabular format

The json can be tricky to read if you get more than a couple of rows.

The function

(show-as-table (query...))

can be used to show results in a tabular, nice format. It will also show time taken to run the query.

Tests

Test can be found in the test.lisp file

They can be run with:

(in-package #:cozodb-test)
 (run! 'test-cozodb)

License

Lisp part is BSD or Apache, your choice.

cozodb-lisp's People

Contributors

pegesund avatar svetlyak40wt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

svetlyak40wt

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.