Skip to main content

No project description provided

Project description

https://img.shields.io/pypi/v/peewee2click.svg https://img.shields.io/pypi/pyversions/peewee2click.svg https://travis-ci.org/buguroo/peewee2click.svg?branch=master

peewee2click is an easy to use Click helper to create command-line CRUDL interfaces for your peewee models.

What are command-line CRUDL interfaces?

Interfaces that let you Create, Read, Update, Delete or List your models via command-line.

Installation

Just run pip install peewee2click.

Example of use

Let supose you have the following peewee class:

import peewee

class MyClass(peewee.Model):
    my_char_field = peewee.CharField(
        max_length=8, help_text="Field to store char.")
    my_int_field = peewee.IntegerField(
        default=5, help_text="Field to store int.")

To create a very basic command-line CRUDL you only need the following code:

from peewee2click import CRUDL
import click

@click.command(help="Creates a new myclass")
@CRUDL.click_options_from_model_fields(MyClass)
def create(**fields):
    CRUDL.create(MyClass, **fields)

@click.command(help="Shows myclass information")
@click.argument("primary_key", type=int)
def show(primary_key):
    CRUDL.show(MyClass, primary_key)

@click.command(help="Updates myclass information")
@click.argument("primary_key")
@CRUDL.click_options_from_model_fields(MyClass)
def update(primary_key, **changed_fields):
    CRUDL.update(MyClass, primary_key, **changed_fields)

@click.command(help="Deletes an existing myclass")
@click.argument("primary_key")
def delete(primary_key):
    CRUDL.delete(MyClass, primary_key)

@click.command("list", help="Enumerate myclasses")
@click.option("fields", "--add-field", multiple=True,
              help="Shows a custom field in the result")
def list_(fields):
    base_fields = ('id', 'my_char_field', 'my_int_field')

    CRUDL.list(MyClass, base_fields, extra_fields=fields)

As you can see, CRUDL.click_options_from_model_fields gathers all the Model fields for you, creating automatically the parameters options “--my-char-field=<new_value>” and “-my-int-field=<new_value>” for the create and update commands.

Other commands

Besides the CRUDL methods seen in the example above, peewee2click also provides two helper functions: one_and_only_one and max_one. Both provide a way of checking that arguments are passed in a proper way.

Check the docstrings of the functions for further information.

Running the tests

Install the develop dependencies: pip install -e requirements/develop.txt. Then run tox.

You will need sqlite support in your Python client to run the tests.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

peewee2click-0.0.4.tar.gz (5.2 kB view details)

Uploaded Source

File details

Details for the file peewee2click-0.0.4.tar.gz.

File metadata

  • Download URL: peewee2click-0.0.4.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for peewee2click-0.0.4.tar.gz
Algorithm Hash digest
SHA256 7f5b5beb426ac1aea41d5fa3852a104bc45f70e2ab1fcf65191b243b248b82ff
MD5 3208721c3bb72ec4f4db7a9eca1f2b87
BLAKE2b-256 e3e48147b6c0d94a40ce93e4e1cbf71b1352b3251a49d8bfc73c9cac27d12d4d

See more details on using hashes here.

Supported by

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