petwee


Namepetwee JSON
Version 0.1.0 PyPI version JSON
download
home_page
Summaryan ORM/ODM for Google Datastore/MongoDB, featuring a compatible interface with Peewee.
upload_time2024-02-05 00:35:19
maintainer
docs_urlNone
author
requires_python>=3.6
licenseMIT License Copyright (c) 2024 cdhigh Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords petwee peewee orm odm google cloud datastore mongodb
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # <img style="vertical-align: top;" src="./logo.png?raw=true" alt="logo" height="50px"> Petwee

[![PyPI version shields.io](https://img.shields.io/pypi/v/petwee.svg)](https://pypi.python.org/pypi/petwee/) ![python](https://img.shields.io/badge/python-3.8+-blue) [![License: MIT](https://img.shields.io/badge/License-MIT%20-blue.svg)](https://github.com/cdhigh/petwee/blob/main/LICENSE)

[![GitHub Release Date](https://img.shields.io/github/release-date-pre/cdhigh/petwee.svg)](https://github.com/cdhigh/petwee/releases) [![Downloads](https://img.shields.io/pypi/dm/petwee.svg)](https://pypi.org/project/petwee/)

The Petwee is a python ODM/ORM module for Google Cloud Datastore and MongoDB, featuring a compatible interface with [Peewee](https://github.com/coleifer/peewee).
It has limited features, with a primary focus on compatibility with the Peewee API.
If you don't use advanced SQL features such as foreign keys or multi-table join queries and more, you can easily switch between SQL and NoSQL without modifying your application code.
I know using NoSQL as if it were SQL is not a very smart idea, but it can achieve maximum compatibility with various databases, so, just choose what you like.



# Quickstart
Alright, if you're already familiar with Peewee, you basically don't need this documentation.
The majority of the content in this document is directly taken from the [official Peewee documentation](http://docs.peewee-orm.com), with minimal alterations. Gratitude is expressed in advance for this.
Additionally, much of the code is also borrowed from Peewee.
Oh, the library name? It seems to be the almost same too: )



## Database client
Petwee supports Google Cloud Datastore and MongoDB. 
To use Google Cloud Datastore, you need to install google-cloud-datastore.   
To use MongoDB, you need to install pymongo.  

```
pip install google-cloud-datastore
pip install pymongo
pip install petwee
```



## Model Definition

```
from petwee import *

db = DatastoreClient(project="project id")
db = MongoDbClient("project id", "mongodb://localhost:27017/")

class Person(Model):
    class Meta:
        database = db

    name = CharField()
    birthday = DateField()
```

The best practice is to define a base class that connects to the database, and then have other models within your application inherit from it.

```
class MyBaseModel(Model):
    class Meta:
        database = db
        useIDInsteadOfKey = True

class Person(MyBaseModel):
    name = CharField()
    birthday = DateField()

class Message(MyBaseModel):
    context = TextField()
    read_count = IntegerField(default=0)
```



## Storing data
Let's begin by populating the database with some people. We will use the save() and create() methods to add and update people's records.

```
from datetime import date
uncle_bob = Person(name='Bob', birthday=date(1960, 1, 15))
uncle_bob.save()
```

You can also add a person by calling the create() method, which returns a model instance. The insert_many() function is a convenient method for adding many data at once:

```
grandma = Person.create(name='Grandma', birthday=date(1935, 3, 1))
Person.insert_many([{'name':'Herb', 'birthday':date(1950, 5, 5)}, {'name':'Adam', 'birthday':date(1990, 9, 1)}])
```

## Counting records
You can count the number of rows in any select query:

```
Tweet.select().count()
Tweet.select().where(Tweet.id > 50).count()
```

## Updating data
To update data, modify the model instance and call save() to persist the changes. Here we will change Grandma's name and then save the changes in the database.
Or you can use an update statement that supports all standard arithmetic operators:

```
grandma.name = 'Grandma L.'
grandma.save()  # Update grandma's name in the database.

Person.update({Person.name: 'Grandma L.'}).where(Person.name == 'Grandma').execute() #Changing to other name
Person.update({Person.name: 'Dear. ' + Person.name}).where(Person.birthday > date(1950, 5, 5)).execute() #Adding a title of respect before someone's name
# update statement supports: +, -, *, /, //, %, **, <<, >>, &, |, ^
```

To delete one or many instances from database:

```
herb.delete_instance()
Person.delete().where(Person.birthday < date(1950, 5, 4)).execute()
```

To remove the whole collection(MongoDb)/kind(datastore), you can use:

```
Person.drop_table()
db.drop_tables([Person, Message])
```

## Retrieving Data

### Getting single records
Let's retrieve Grandma's record from the database. To get a single record from the database, use Select.get():

```
grandma = Person.get(Person.name == 'Grandma L.')
grandma = Person.select().where(Person.name == 'Grandma L.').get()
grandma = Person.select().where(Person.name == 'Grandma L.').first()
grandma = Person.select().where(Person.name == 'Grandma L.').get_or_none()
grandma = Person.get_by_id('65bda09d6efd9b1130ffccb0')
grandma = Person.select().where(Person.id == '65bda09d6efd9b1130ffccb0').first()
```

```
grandma = Person.select(Person.name, Person.birthday).where(Person.name == 'Grandma L.').first()
```

The code lines above return an instance of the Model. If, in some situations, you need a dictionary, you can use dicts() to return a standard Python dictionary.

```
grandma.dicts()
grandma.dicts(only=[Person.name, Person.birthday])
grandma.dicts(exclude=[Person.birthday])
grandma.dicts(remove_id=True)
```



### Lists of records
Let's list all the people in the database:

```
for person in Person.select():
    print(person.name)

for person in Person.select().where(Person.birthday <= date(1960, 1, 15)):
    print(person.name)
```



### Sorting
Let's make sure these are sorted alphabetically by adding an order_by() clause:

```
for person in Person.select().where(Person.birthday <= date(1960, 1, 15)).order_by(Person.name):
    print(person.name)

for person in Person.select().order_by(Person.birthday.desc()):
    print(person.name, person.birthday)
```



### Combining filter expressions

People whose birthday is between 1940 and 1960 (inclusive of both years):

```
d1940 = date(1940, 1, 1)
d1960 = date(1960, 1, 1)
query = Person.select().where((Person.birthday > d1940) & (Person.birthday < d1960))
for person in query:
    print(person.name, person.birthday)

#alternative methods
query = Person.select().where(Person.birthday.between(d1940, d1960))
query = Person.select().where(Person.birthday > d1940).where(Person.birthday < d1960)
```


# Models and Fields

## Field types supported:
* IntegerField
* BigIntegerField
* SmallIntegerField
* FloatField
* DoubleField
* DecimalField
* CharField
* FixedCharField
* TextField
* BlobField
* UUIDField
* JSONField


## Reserved field names
The following names of fields reserved by the model, should be avoided for your fields:   

```_key, _id, id```

## Field initialization arguments
Parameters accepted by all field types and their default values:
* `default = None` – any value or callable to use as a default for uninitialized models
* `enforce_type = False` – determine if the new value is of a specific type.

Other parameters accepted by Peewee can be passed, Petwee simply ignores them in a straightforward manner.



## Default field values
Petwee can provide default values for fields when objects are created. For example to have an IntegerField default to zero rather than NULL, you could declare the field with a default value:

```
class Message(Model):
    context = TextField()
    read_count = IntegerField(default=0)
```

In some instances it may make sense for the default value to be dynamic. A common scenario is using the current date and time. Petwee allows you to specify a function in these cases, whose return value will be used when the object is created. Note we only provide the function, we do not actually call it:

```
class Message(Model):
    context = TextField()
    timestamp = DateTimeField(default=datetime.datetime.now)
```

Note:
If you are using a field that accepts a mutable type (list, dict, etc), and would like to provide a default, it is a good idea to wrap your default value in a simple function so that multiple model instances are not sharing a reference to the same underlying object:

```
def house_defaults():
    return {'beds': 0, 'baths': 0}

class House(Model):
    number = TextField()
    street = TextField()
    attributes = JSONField(default=house_defaults)
```



## Creating a custom field
It is easy to add support for custom field types in petwee. In this example we will create a StringyBooleanField.

```
class StringyBooleanField(Field):
    def db_value(self, value): #The return value will be stored in database
        return "True" if value else "False"

    def python_value(self, value): #The return value will be used in python app code
        return value == "True"
```



## Model options and table metadata
In order not to pollute the model namespace, model-specific configuration is placed in a special class called Meta (a convention borrowed from the django framework):

```
db = MongoDbClient("project id", "mongodb://localhost:27017/")

class Person(Model):
    name = CharField()
    birthday = DateField()

    class Meta:
        database = db
```

Once the class is defined, you should not access ModelClass.Meta, but instead use ModelClass.\_meta:

```
Person.Meta
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'Person' has no attribute 'Meta'

Person._meta
<petwee.ModelOptions object at 0x7f51a2f03790>
```

The ModelOptions class implements several methods which may be of use for retrieving model metadata.

```
Person._meta.fields
Person._meta.client
```
Now, the ModelOptions accepts two parameters:
* database: indicating the backend database client instance to be used
* primary_key: Optional, the name of the primary key at the underlying level of each database is different. For Datastore, it's called "key", for MongoDB, it's "\_id", To ensure compatibility with SQL and simplify application code, Petwee automatically adds a primary key named 'id' with a string type. This primary key is only an application-level attribute variable and will not be saved to the underlying database.
If this name conflicts with your application, you can use the "primary_key" attribute to modify it, for example:

```
class Meta
    database = db
    primary_key = 'id_'
```


# Querying

## Selecting a single record

```
User.get_by_id('65bda09d6efd9b1130ffccb0')
User.get(User.username == 'Charlie')
User.select().where(User.username.in_(['Charlie', 'Adam'])).order_by(User.birthday.desc()).get()
```


## Filtering records
You can filter for particular records using normal python operators. Petwee supports a wide variety of query operators.

### Query operators
The following types of comparisons are supported by petwee:

| Comparison     | Meaning                         |
|----------------|---------------------------------|
| ==             | x equals y                      |
| <              | x is less than y                |
| <=             | x is less than or equal to y    |
| >              | x is greater than y             |
| >=             | x is greater than or equal to y |
| !=             | x is not equal to y             |
| .in_(list)     | IN lookup                       |
| .not_in(list)  | NOT IN lookup.                  |
| &              | Query logical AND               |




### Some extra examples

```
user = User.select().where(User.name == 'python').get()
user = User.select().where(User.name == 'python').first()
user = User.select().where(User.name.in_(['python', 'cobra'])).first()
user = User.select().where(User.name.not_in(['python', 'cobra'])).first()
users = User.select(User.name, User.score).where(User.name == 'python').execute()
users = User.select().where(User.birthdate.between(datetime.datetime(2024,1,1), datetime.datetime(2024,2,1))).execute()
user = User.select().where((User.name != 'python') & (User.name != 'cobra')).first()
user = User.select().where(User.name != 'python').where(User.name != 'cobra').first()
User.select().order_by(User.birthdate.desc(), User.score).limit(10).execute()

User.update({User.score: User.att_days + (User.evaluation * 2)}).where(User.age < 10).execute()

```



            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "petwee",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "petwee,peewee,ORM,ODM,google cloud datastore,MongoDB",
    "author": "",
    "author_email": "cdhigh <chsqyuan@gmail.com>",
    "download_url": "",
    "platform": null,
    "description": "# <img style=\"vertical-align: top;\" src=\"./logo.png?raw=true\" alt=\"logo\" height=\"50px\"> Petwee\r\n\r\n[![PyPI version shields.io](https://img.shields.io/pypi/v/petwee.svg)](https://pypi.python.org/pypi/petwee/) ![python](https://img.shields.io/badge/python-3.8+-blue) [![License: MIT](https://img.shields.io/badge/License-MIT%20-blue.svg)](https://github.com/cdhigh/petwee/blob/main/LICENSE)\r\n\r\n[![GitHub Release Date](https://img.shields.io/github/release-date-pre/cdhigh/petwee.svg)](https://github.com/cdhigh/petwee/releases) [![Downloads](https://img.shields.io/pypi/dm/petwee.svg)](https://pypi.org/project/petwee/)\r\n\r\nThe Petwee is a python ODM/ORM module for Google Cloud Datastore and MongoDB, featuring a compatible interface with [Peewee](https://github.com/coleifer/peewee).\r\nIt has limited features, with a primary focus on compatibility with the Peewee API.\r\nIf you don't use advanced SQL features such as foreign keys or multi-table join queries and more, you can easily switch between SQL and NoSQL without modifying your application code.\r\nI know using NoSQL as if it were SQL is not a very smart idea, but it can achieve maximum compatibility with various databases, so, just choose what you like.\r\n\r\n\r\n\r\n# Quickstart\r\nAlright, if you're already familiar with Peewee, you basically don't need this documentation.\r\nThe majority of the content in this document is directly taken from the [official Peewee documentation](http://docs.peewee-orm.com), with minimal alterations. Gratitude is expressed in advance for this.\r\nAdditionally, much of the code is also borrowed from Peewee.\r\nOh, the library name? It seems to be the almost same too: )\r\n\r\n\r\n\r\n## Database client\r\nPetwee supports Google Cloud Datastore and MongoDB. \r\nTo use Google Cloud Datastore, you need to install google-cloud-datastore.   \r\nTo use MongoDB, you need to install pymongo.  \r\n\r\n```\r\npip install google-cloud-datastore\r\npip install pymongo\r\npip install petwee\r\n```\r\n\r\n\r\n\r\n## Model Definition\r\n\r\n```\r\nfrom petwee import *\r\n\r\ndb = DatastoreClient(project=\"project id\")\r\ndb = MongoDbClient(\"project id\", \"mongodb://localhost:27017/\")\r\n\r\nclass Person(Model):\r\n    class Meta:\r\n        database = db\r\n\r\n    name = CharField()\r\n    birthday = DateField()\r\n```\r\n\r\nThe best practice is to define a base class that connects to the database, and then have other models within your application inherit from it.\r\n\r\n```\r\nclass MyBaseModel(Model):\r\n    class Meta:\r\n        database = db\r\n        useIDInsteadOfKey = True\r\n\r\nclass Person(MyBaseModel):\r\n    name = CharField()\r\n    birthday = DateField()\r\n\r\nclass Message(MyBaseModel):\r\n    context = TextField()\r\n    read_count = IntegerField(default=0)\r\n```\r\n\r\n\r\n\r\n## Storing data\r\nLet's begin by populating the database with some people. We will use the save() and create() methods to add and update people's records.\r\n\r\n```\r\nfrom datetime import date\r\nuncle_bob = Person(name='Bob', birthday=date(1960, 1, 15))\r\nuncle_bob.save()\r\n```\r\n\r\nYou can also add a person by calling the create() method, which returns a model instance. The insert_many() function is a convenient method for adding many data at once:\r\n\r\n```\r\ngrandma = Person.create(name='Grandma', birthday=date(1935, 3, 1))\r\nPerson.insert_many([{'name':'Herb', 'birthday':date(1950, 5, 5)}, {'name':'Adam', 'birthday':date(1990, 9, 1)}])\r\n```\r\n\r\n## Counting records\r\nYou can count the number of rows in any select query:\r\n\r\n```\r\nTweet.select().count()\r\nTweet.select().where(Tweet.id > 50).count()\r\n```\r\n\r\n## Updating data\r\nTo update data, modify the model instance and call save() to persist the changes. Here we will change Grandma's name and then save the changes in the database.\r\nOr you can use an update statement that supports all standard arithmetic operators:\r\n\r\n```\r\ngrandma.name = 'Grandma L.'\r\ngrandma.save()  # Update grandma's name in the database.\r\n\r\nPerson.update({Person.name: 'Grandma L.'}).where(Person.name == 'Grandma').execute() #Changing to other name\r\nPerson.update({Person.name: 'Dear. ' + Person.name}).where(Person.birthday > date(1950, 5, 5)).execute() #Adding a title of respect before someone's name\r\n# update statement supports: +, -, *, /, //, %, **, <<, >>, &, |, ^\r\n```\r\n\r\nTo delete one or many instances from database:\r\n\r\n```\r\nherb.delete_instance()\r\nPerson.delete().where(Person.birthday < date(1950, 5, 4)).execute()\r\n```\r\n\r\nTo remove the whole collection(MongoDb)/kind(datastore), you can use:\r\n\r\n```\r\nPerson.drop_table()\r\ndb.drop_tables([Person, Message])\r\n```\r\n\r\n## Retrieving Data\r\n\r\n### Getting single records\r\nLet's retrieve Grandma's record from the database. To get a single record from the database, use Select.get():\r\n\r\n```\r\ngrandma = Person.get(Person.name == 'Grandma L.')\r\ngrandma = Person.select().where(Person.name == 'Grandma L.').get()\r\ngrandma = Person.select().where(Person.name == 'Grandma L.').first()\r\ngrandma = Person.select().where(Person.name == 'Grandma L.').get_or_none()\r\ngrandma = Person.get_by_id('65bda09d6efd9b1130ffccb0')\r\ngrandma = Person.select().where(Person.id == '65bda09d6efd9b1130ffccb0').first()\r\n```\r\n\r\n```\r\ngrandma = Person.select(Person.name, Person.birthday).where(Person.name == 'Grandma L.').first()\r\n```\r\n\r\nThe code lines above return an instance of the Model. If, in some situations, you need a dictionary, you can use dicts() to return a standard Python dictionary.\r\n\r\n```\r\ngrandma.dicts()\r\ngrandma.dicts(only=[Person.name, Person.birthday])\r\ngrandma.dicts(exclude=[Person.birthday])\r\ngrandma.dicts(remove_id=True)\r\n```\r\n\r\n\r\n\r\n### Lists of records\r\nLet's list all the people in the database:\r\n\r\n```\r\nfor person in Person.select():\r\n    print(person.name)\r\n\r\nfor person in Person.select().where(Person.birthday <= date(1960, 1, 15)):\r\n    print(person.name)\r\n```\r\n\r\n\r\n\r\n### Sorting\r\nLet's make sure these are sorted alphabetically by adding an order_by() clause:\r\n\r\n```\r\nfor person in Person.select().where(Person.birthday <= date(1960, 1, 15)).order_by(Person.name):\r\n    print(person.name)\r\n\r\nfor person in Person.select().order_by(Person.birthday.desc()):\r\n    print(person.name, person.birthday)\r\n```\r\n\r\n\r\n\r\n### Combining filter expressions\r\n\r\nPeople whose birthday is between 1940 and 1960 (inclusive of both years):\r\n\r\n```\r\nd1940 = date(1940, 1, 1)\r\nd1960 = date(1960, 1, 1)\r\nquery = Person.select().where((Person.birthday > d1940) & (Person.birthday < d1960))\r\nfor person in query:\r\n    print(person.name, person.birthday)\r\n\r\n#alternative methods\r\nquery = Person.select().where(Person.birthday.between(d1940, d1960))\r\nquery = Person.select().where(Person.birthday > d1940).where(Person.birthday < d1960)\r\n```\r\n\r\n\r\n# Models and Fields\r\n\r\n## Field types supported:\r\n* IntegerField\r\n* BigIntegerField\r\n* SmallIntegerField\r\n* FloatField\r\n* DoubleField\r\n* DecimalField\r\n* CharField\r\n* FixedCharField\r\n* TextField\r\n* BlobField\r\n* UUIDField\r\n* JSONField\r\n\r\n\r\n## Reserved field names\r\nThe following names of fields reserved by the model, should be avoided for your fields:   \r\n\r\n```_key, _id, id```\r\n\r\n## Field initialization arguments\r\nParameters accepted by all field types and their default values:\r\n* `default = None` \u2013 any value or callable to use as a default for uninitialized models\r\n* `enforce_type = False` \u2013 determine if the new value is of a specific type.\r\n\r\nOther parameters accepted by Peewee can be passed, Petwee simply ignores them in a straightforward manner.\r\n\r\n\r\n\r\n## Default field values\r\nPetwee can provide default values for fields when objects are created. For example to have an IntegerField default to zero rather than NULL, you could declare the field with a default value:\r\n\r\n```\r\nclass Message(Model):\r\n    context = TextField()\r\n    read_count = IntegerField(default=0)\r\n```\r\n\r\nIn some instances it may make sense for the default value to be dynamic. A common scenario is using the current date and time. Petwee allows you to specify a function in these cases, whose return value will be used when the object is created. Note we only provide the function, we do not actually call it:\r\n\r\n```\r\nclass Message(Model):\r\n    context = TextField()\r\n    timestamp = DateTimeField(default=datetime.datetime.now)\r\n```\r\n\r\nNote:\r\nIf you are using a field that accepts a mutable type (list, dict, etc), and would like to provide a default, it is a good idea to wrap your default value in a simple function so that multiple model instances are not sharing a reference to the same underlying object:\r\n\r\n```\r\ndef house_defaults():\r\n    return {'beds': 0, 'baths': 0}\r\n\r\nclass House(Model):\r\n    number = TextField()\r\n    street = TextField()\r\n    attributes = JSONField(default=house_defaults)\r\n```\r\n\r\n\r\n\r\n## Creating a custom field\r\nIt is easy to add support for custom field types in petwee. In this example we will create a StringyBooleanField.\r\n\r\n```\r\nclass StringyBooleanField(Field):\r\n    def db_value(self, value): #The return value will be stored in database\r\n        return \"True\" if value else \"False\"\r\n\r\n    def python_value(self, value): #The return value will be used in python app code\r\n        return value == \"True\"\r\n```\r\n\r\n\r\n\r\n## Model options and table metadata\r\nIn order not to pollute the model namespace, model-specific configuration is placed in a special class called Meta (a convention borrowed from the django framework):\r\n\r\n```\r\ndb = MongoDbClient(\"project id\", \"mongodb://localhost:27017/\")\r\n\r\nclass Person(Model):\r\n    name = CharField()\r\n    birthday = DateField()\r\n\r\n    class Meta:\r\n        database = db\r\n```\r\n\r\nOnce the class is defined, you should not access ModelClass.Meta, but instead use ModelClass.\\_meta:\r\n\r\n```\r\nPerson.Meta\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\nAttributeError: type object 'Person' has no attribute 'Meta'\r\n\r\nPerson._meta\r\n<petwee.ModelOptions object at 0x7f51a2f03790>\r\n```\r\n\r\nThe ModelOptions class implements several methods which may be of use for retrieving model metadata.\r\n\r\n```\r\nPerson._meta.fields\r\nPerson._meta.client\r\n```\r\nNow, the ModelOptions accepts two parameters:\r\n* database: indicating the backend database client instance to be used\r\n* primary_key: Optional, the name of the primary key at the underlying level of each database is different. For Datastore, it's called \"key\", for MongoDB, it's \"\\_id\", To ensure compatibility with SQL and simplify application code, Petwee automatically adds a primary key named 'id' with a string type. This primary key is only an application-level attribute variable and will not be saved to the underlying database.\r\nIf this name conflicts with your application, you can use the \"primary_key\" attribute to modify it, for example:\r\n\r\n```\r\nclass Meta\r\n    database = db\r\n    primary_key = 'id_'\r\n```\r\n\r\n\r\n# Querying\r\n\r\n## Selecting a single record\r\n\r\n```\r\nUser.get_by_id('65bda09d6efd9b1130ffccb0')\r\nUser.get(User.username == 'Charlie')\r\nUser.select().where(User.username.in_(['Charlie', 'Adam'])).order_by(User.birthday.desc()).get()\r\n```\r\n\r\n\r\n## Filtering records\r\nYou can filter for particular records using normal python operators. Petwee supports a wide variety of query operators.\r\n\r\n### Query operators\r\nThe following types of comparisons are supported by petwee:\r\n\r\n| Comparison     | Meaning                         |\r\n|----------------|---------------------------------|\r\n| ==             | x equals y                      |\r\n| <              | x is less than y                |\r\n| <=             | x is less than or equal to y    |\r\n| >              | x is greater than y             |\r\n| >=             | x is greater than or equal to y |\r\n| !=             | x is not equal to y             |\r\n| .in_(list)     | IN lookup                       |\r\n| .not_in(list)  | NOT IN lookup.                  |\r\n| &              | Query logical AND               |\r\n\r\n\r\n\r\n\r\n### Some extra examples\r\n\r\n```\r\nuser = User.select().where(User.name == 'python').get()\r\nuser = User.select().where(User.name == 'python').first()\r\nuser = User.select().where(User.name.in_(['python', 'cobra'])).first()\r\nuser = User.select().where(User.name.not_in(['python', 'cobra'])).first()\r\nusers = User.select(User.name, User.score).where(User.name == 'python').execute()\r\nusers = User.select().where(User.birthdate.between(datetime.datetime(2024,1,1), datetime.datetime(2024,2,1))).execute()\r\nuser = User.select().where((User.name != 'python') & (User.name != 'cobra')).first()\r\nuser = User.select().where(User.name != 'python').where(User.name != 'cobra').first()\r\nUser.select().order_by(User.birthdate.desc(), User.score).limit(10).execute()\r\n\r\nUser.update({User.score: User.att_days + (User.evaluation * 2)}).where(User.age < 10).execute()\r\n\r\n```\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 cdhigh  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "an ORM/ODM for Google Datastore/MongoDB, featuring a compatible interface with Peewee.",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/cdhigh/petwee"
    },
    "split_keywords": [
        "petwee",
        "peewee",
        "orm",
        "odm",
        "google cloud datastore",
        "mongodb"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "02aa6009d6b30604d324d1067f3f441ed7a1243548526a08da6547c8fdd733ee",
                "md5": "66a613325f159e8c79ebc7bacd8d92bb",
                "sha256": "07ae4bd36b086048757ba6eecac8f7fe80fd8b5b63178f1cc3fa7934d434125f"
            },
            "downloads": -1,
            "filename": "petwee-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "66a613325f159e8c79ebc7bacd8d92bb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 14445,
            "upload_time": "2024-02-05T00:35:19",
            "upload_time_iso_8601": "2024-02-05T00:35:19.382022Z",
            "url": "https://files.pythonhosted.org/packages/02/aa/6009d6b30604d324d1067f3f441ed7a1243548526a08da6547c8fdd733ee/petwee-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-05 00:35:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cdhigh",
    "github_project": "petwee",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "petwee"
}
        
Elapsed time: 0.43854s