Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github /ISSUE_TEMPLATE/2-bug-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
name: Bug report
about: Report a bug to help improve this project
---

### Checklist

<!-- Please make sure you check all these items before submitting your bug report. -->

- [ ] The bug is reproducible against the latest release and/or `master`.
- [ ] There are no similar issues or pull requests to fix it yet.

### Describe the bug

<!-- A clear and concise description of what the bug is. -->

### To reproduce

<!-- Provide a *minimal* example with steps to reproduce the bug locally.

NOTE: try to keep any external dependencies *at an absolute minimum*
(middleware, servers, proxies, certificates...).
In other words, remove anything that doesn't make the bug go away.
-->

### Expected behavior

<!-- A clear and concise description of what you expected to happen. -->

### Actual behavior

<!-- A clear and concise description of what actually happens. -->

### Debugging material

<!-- Any tracebacks, screenshots, etc. that can help understanding the problem.

NOTE:
- Please list tracebacks in full (don't truncate them).
- Consider using `<details>` to make tracebacks/logs collapsible if they're very large (see https://gist.github.com/ericclemmons/b146fe5da72ca1f706b2ef72a20ac39d).
-->

### Environment

- OS: <!-- eg Linux/Windows/macOS. -->
- Python version: <!-- eg 3.8.5 (get it with `$ python -V`). -->
- ORM version: <!-- eg 0.13.8 (get it with `$ pip show orm`). -->

### Additional context

<!-- Any additional information that can help understanding the problem.

Eg. linked issues, or a description of what you were trying to achieve. -->
33 changes: 33 additions & 0 deletions .github /ISSUE_TEMPLATE/3-feature-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: Feature request
about: Suggest an idea for this project.
---

### Checklist

<!-- Please make sure you check all these items before submitting your feature request. -->

- [ ] There are no similar issues or pull requests for this yet.
- [ ] I discussed this idea on the [community chat](https://gitter.im/encode/community) and feedback is positive.

### Is your feature related to a problem? Please describe.

<!-- A clear and concise description of what you are trying to achieve.

Eg "I want to be able to [...] but I can't because [...]". -->

## Describe the solution you would like.

<!-- A clear and concise description of what you would want to happen.

For API changes, try to provide a code snippet of what you would like the API to look like.
-->

## Describe alternatives you considered

<!-- Please describe any alternative solutions or features you've considered to solve
your problem and why they wouldn't solve it. -->

## Additional context

<!-- Provide any additional context, screenshots, tracebacks, etc. about the feature here. -->
7 changes: 7 additions & 0 deletions .github /ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Ref: https://help.github.com/en/github/building-a-strong-community/configuring-issue-templates-for-your-repository#configuring-the-template-chooser
blank_issues_enabled: true
contact_links:
- name: Question
url: https://gitter.im/encode/community
about: >
Ask a question
27 changes: 27 additions & 0 deletions .github /workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Publish

on:
push:
tags:
- '*'

jobs:
publish:
name: "Publish release"
runs-on: "ubuntu-latest"

steps:
- uses: "actions/checkout@v2"
- uses: "actions/setup-python@v2"
with:
python-version: 3.7
- name: "Install dependencies"
run: "scripts/install"
- name: "Build package & docs"
run: "scripts/build"
- name: "Publish to PyPI & deploy docs"
run: "scripts/publish"
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
33 changes: 33 additions & 0 deletions .github /workflows/test-suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: Test Suite

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

jobs:
tests:
name: "Python ${{ matrix.python-version }}"
runs-on: "ubuntu-latest"

strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10.0-beta.3"]

steps:
- uses: "actions/checkout@v2"
- uses: "actions/setup-python@v2"
with:
python-version: "${{ matrix.python-version }}"
- name: "Install dependencies"
run: "scripts/install"
- name: "Run linting checks"
run: "scripts/check"
- name: "Build package & docs"
run: "scripts/build"
- name: "Run tests"
run: "scripts/test"
- name: "Enforce coverage"
run: "scripts/coverage"
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# ORM

<p>
<a href="https://travis-ci.org/encode/orm">
<img src="https://travis-ci.org/encode/orm.svg?branch=master" alt="Build Status">
<a href="https://github.com/encode/orm/actions">
<img src="https://github.com/encode/orm/workflows/Test%20Suite/badge.svg" alt="Build Status">
</a>
<a href="https://codecov.io/gh/encode/orm">
<img src="https://codecov.io/gh/encode/orm/branch/master/graph/badge.svg" alt="Coverage">
Expand Down
13 changes: 12 additions & 1 deletion orm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
from orm.exceptions import MultipleMatches, NoMatch
from orm.fields import Boolean, Integer, Float, String, Text, Date, Time, DateTime, JSON, ForeignKey
from orm.fields import (
JSON,
Boolean,
Date,
DateTime,
Float,
ForeignKey,
Integer,
String,
Text,
Time,
)
from orm.models import Model

__version__ = "0.1.4"
Expand Down
32 changes: 19 additions & 13 deletions orm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from typesystem.schemas import SchemaMetaclass

from orm.exceptions import MultipleMatches, NoMatch
from orm.fields import ForeignKey


FILTER_OPERATORS = {
"exact": "__eq__",
Expand Down Expand Up @@ -49,8 +47,16 @@ def __new__(


class QuerySet:
ESCAPE_CHARACTERS = ['%', '_']
def __init__(self, model_cls=None, filter_clauses=None, select_related=None, limit_count=None, offset=None):
ESCAPE_CHARACTERS = ["%", "_"]

def __init__(
self,
model_cls=None,
filter_clauses=None,
select_related=None,
limit_count=None,
offset=None,
):
self.model_cls = model_cls
self.filter_clauses = [] if filter_clauses is None else filter_clauses
self._select_related = [] if select_related is None else select_related
Expand Down Expand Up @@ -145,27 +151,28 @@ def filter(self, **kwargs):
has_escaped_character = False

if op in ["contains", "icontains"]:
has_escaped_character = any(c for c in self.ESCAPE_CHARACTERS
if c in value)
has_escaped_character = any(
c for c in self.ESCAPE_CHARACTERS if c in value
)
if has_escaped_character:
# enable escape modifier
for char in self.ESCAPE_CHARACTERS:
value = value.replace(char, f'\\{char}')
value = value.replace(char, f"\\{char}")
value = f"%{value}%"

if isinstance(value, Model):
value = value.pk

clause = getattr(column, op_attr)(value)
clause.modifiers['escape'] = '\\' if has_escaped_character else None
clause.modifiers["escape"] = "\\" if has_escaped_character else None
filter_clauses.append(clause)

return self.__class__(
model_cls=self.model_cls,
filter_clauses=filter_clauses,
select_related=select_related,
limit_count=self.limit_count,
offset=self.query_offset
offset=self.query_offset,
)

def select_related(self, related):
Expand All @@ -178,7 +185,7 @@ def select_related(self, related):
filter_clauses=self.filter_clauses,
select_related=related,
limit_count=self.limit_count,
offset=self.query_offset
offset=self.query_offset,
)

async def exists(self) -> bool:
Expand All @@ -192,17 +199,16 @@ def limit(self, limit_count: int):
filter_clauses=self.filter_clauses,
select_related=self._select_related,
limit_count=limit_count,
offset=self.query_offset
offset=self.query_offset,
)


def offset(self, offset: int):
return self.__class__(
model_cls=self.model_cls,
filter_clauses=self.filter_clauses,
select_related=self._select_related,
limit_count=self.limit_count,
offset=offset
offset=offset,
)

async def count(self) -> int:
Expand Down
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
databases[sqlite]
typesystem

# Packaging
twine
wheel

# Testing
autoflake
black
codecov
flake8
isort
mypy
pytest
Expand Down
13 changes: 13 additions & 0 deletions scripts/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh -e

if [ -d 'venv' ] ; then
PREFIX="venv/bin/"
else
PREFIX=""
fi

set -x

${PREFIX}python setup.py sdist bdist_wheel
${PREFIX}twine check dist/*
# ${PREFIX}mkdocs build
14 changes: 14 additions & 0 deletions scripts/check
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh -e

export PREFIX=""
if [ -d 'venv' ] ; then
export PREFIX="venv/bin/"
fi
export SOURCE_FILES="orm tests"

set -x

${PREFIX}isort --check --diff --project=orm $SOURCE_FILES
${PREFIX}black --check --diff $SOURCE_FILES
${PREFIX}flake8 $SOURCE_FILES
# ${PREFIX}mypy $SOURCE_FILES
10 changes: 10 additions & 0 deletions scripts/coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh -e

export PREFIX=""
if [ -d 'venv' ] ; then
export PREFIX="venv/bin/"
fi

set -x

${PREFIX}coverage report --show-missing --skip-covered --fail-under=100
10 changes: 10 additions & 0 deletions scripts/docs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh -e

export PREFIX=""
if [ -d 'venv' ] ; then
export PREFIX="venv/bin/"
fi

set -x

${PREFIX}mkdocs serve
18 changes: 14 additions & 4 deletions scripts/install
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
#!/bin/sh -e

[[ $1 = "-p" ]] && PYTHON=$2 || PYTHON="python3"
# Use the Python executable provided from the `-p` option, or a default.
[ "$1" = "-p" ] && PYTHON=$2 || PYTHON="python3"

REQUIREMENTS="requirements.txt"
VENV="venv"

set -x

"$PYTHON" -m venv venv
venv/bin/pip install -U -r requirements.txt
venv/bin/pip install -e .
if [ -z "$GITHUB_ACTIONS" ]; then
"$PYTHON" -m venv "$VENV"
PIP="$VENV/bin/pip"
else
PIP="pip"
fi

"$PIP" install -r "$REQUIREMENTS"
"$PIP" install -e .
Loading