Giter Club home page Giter Club logo

pyrqlite's Introduction

pyrqlite

This package contains a pure-Python rqlite client library.

  • Python -- one of the following:
  • rqlite Server

The last stable release is available on github and can be installed with pip:

$ cd
$ git clone https://github.com/rqlite/pyrqlite.git
$ pip install ./pyrqlite

Alternatively (e.g. if pip is not available), a tarball can be downloaded from GitHub and installed with Setuptools:

$ # X.X is the desired pyrqlite version (e.g. 0.5 or 0.6).
$ curl -L https://github.com/rqlite/tarball/pyrqlite-X.X | tar xz
$ cd pyrqlite*
$ python setup.py install
$ # The folder pyrqlite* can be safely removed now.

To run all the tests, execute the script setup.py:

$ python setup.py test

pytest (https://pytest.org/) and pytest-cov are required to run the test suite. They can both be installed with pip

The following code creates a connection and executes some statements:

import pyrqlite.dbapi2 as dbapi2

# Connect to the database
connection = dbapi2.connect(
    host='localhost',
    port=4001,
)

try:
    with connection.cursor() as cursor:
        cursor.execute('CREATE TABLE foo (id integer not null primary key, name text)')
        cursor.executemany('INSERT INTO foo(name) VALUES(?)', seq_of_parameters=(('a',), ('b',)))

    with connection.cursor() as cursor:
        # Read a single record with qmark parameter style
        sql = "SELECT `id`, `name` FROM `foo` WHERE `name`=?"
        cursor.execute(sql, ('a',))
        result = cursor.fetchone()
        print(result)
        # Read a single record with named parameter style
        sql = "SELECT `id`, `name` FROM `foo` WHERE `name`=:name"
        cursor.execute(sql, {'name': 'b'})
        result = cursor.fetchone()
        print(result)
finally:
    connection.close()

This example will print:

OrderedDict([('id', 1), ('name', 'a')]) OrderedDict([('id', 2), ('name', 'b')])

Only qmark and named paramstyles (as defined in PEP 249) are supported.

Transactions are not supported.

DB-API 2.0: http://www.python.org/dev/peps/pep-0249

pyrqlite is released under the MIT License. See LICENSE for more information.

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.