Coder Social home page Coder Social logo

vino's Introduction

Vino

VINO Is Not ORM. Yes, it's true, it's not ORM.

Get Started

A quick view with Vino:

# setup
# db = Vino('engine://user:passwd@host:port/database')
db = Vino('sqlite://db.sqlite')

# query
db.table('user').find(username='lepture').fetch()

# create
db.table('user').create(username='lepture', website='http://lepture.com')
db.commit()

# update
db.table('user').find(username='lepture').update(username='Hsiaoming Yang')
db.commit()

# delete
db.table('user').find(username='lepture').delete()
db.commit()

Setup

We will only support sqlite3 and mysql by now.

SQLite

SQLite with relative path:

db = Vino('sqlite://relative/path/db.sqlite')

SQLite with absolute path:

db = Vino('sqlite:///root/path/db.sqlite')

Please note, it's different from SQLAlchemy.

MySQL

MySQL with all information:

db = Vino('mysql://lepture:123456@localhost:3306/test')

MySQL with less information:

db = Vino('mysql://lepture@localhost/test')

Default port is 3306.

Please note, it's utf8 by default.

Query

Find all data:

db.table('user').fetch()

Find all specified data:

db.table('user').find(username='lepture').fetch()

Find the first data:

# fetch 1 will not return a list
db.table('user').find(username='lepture').fetch(1)

Limit on query:

db.table('user').find(username='lepture').fetch(5, offset=3)

Multiple filters:

db.table('user').find(username='lepture', age=20).fetch()

Advanced filters:

# just like Django

db.table('user').find(age__in=[20, 22]).fetch()
db.table('user').find(age__gt=20).fetch()
db.table('user').find(age__lt=20).fetch()
db.table('user').find(age__gte=20).fetch()
db.table('user').find(age__lte=20).fetch()

# more see documentation

More Advanced filters:

db.table('user').find(age__ne=20).fetch()  # not equal
db.table('user').find(age__nin=[20, 22]).fetch()  # not in

# more see documentation

Query order:

db.table('user').find(age=20).order('-id').fetch()

Create

Update

Delete

Delete all data:

db.table('user').delete()
db.commit()

Delete specified data:

db.table('user').find(username='lepture').delete()
db.commit()

Describe

Describe a table:

db.table('user').describe()

# return
{
    "columns": {
        "id": {
            "type": "integer",
            "null": False,
        },
        "username": {
            "type": "varchar",
            "length": 50,
            "null": False,
            "unique": True,
        },
        "email": {
            "type": "varchar",
            "length": 200,
            "null": False,
            "unique": True,
        },
        "created": {
            "type": "datetime"
        }
    },
    "index": [
        "username",
    ],
    "primary": "id",
}

FAQ

  1. How do I join tables?

    Vino provides clean and simple API, you should join tables yourself with db.raw

vino's People

Contributors

freeyoung avatar

Watchers

 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.