Skip to main content

Redice SQLAlchemy Boost Library. It's based sqlalchemy-wrapper

Project description

Redice SQLAlchemy Boost Library. It’s based sqlalchemy-wrapper.

1. declaring plavin

from palvin import Palvin

db = Palvin(uri='sqlite:///:memory:')

class ToDo(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    ...

db.create_all()
todos = Todo.query.all()

2. palvin-attachement

Inspired by sqlalchemy-imageattach.

declaring attachment model.

# -*- coding:utf-8 -*-
from palvin import (
    Palvin,
    FileSystemStore,
    PalvinFile,
    PalvinImage,
    file_relationship,
    image_relationship
)

store = FileSystemStore('/tmp/uploads')
db = Palvin(uri='sqlite:///:memory:', store=store)

from palvin import file_relationship, image_relationship, PalvinFile, PalvinImage


class UserPicture(db.Model, PalvinImage):
    pass


class File(db.Model, PalvinFile):
    pass


class User(db.Model):
    picture = image_relationship(UserPicture)
    file = file_relationship(File)

create

u = User.create(picture=UserPicture.from_file(open('/tmp/test.jpg', 'rb')))
u.save()

update

u = User.get(1)
u.picture = UserPicture.from_file(open('/tmp/test.jpg', 'rb'))
u.save()

delete

u = User.get(1)
u.picture = None
u.save()

Project details


Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page