Coder Social home page Coder Social logo

pypika-tortoise's People

Contributors

jameswinegar avatar kanagawanezumi avatar long2ice avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pypika-tortoise's Issues

UpdateQuery produces invalid SQL statement on Joins

Say you have a query like this:

await Student.all().update(school=school2)

this will produce

UPDATE "student" SET "school_id"=?

It will also work perfectly fine if we filter on the same table, like so:

Student.filter(name='test').update(school=school2).as_query()

which produces

UPDATE "student" SET "school_id"=? WHERE "name"='test'

However, if we join a table to filter on for the update, it gets the order wrong. So this

Student.filter(school__id=school2.id).update(name="test").as_query()

produces

UPDATE "student" 
LEFT OUTER JOIN "school" "student__school" ON "student__school"."id"="student"."school_id" 
SET "name"=? 
WHERE "student__school"."id"=2048

The correct sql statement for this would be

UPDATE "student" 
SET "name"=? 
FROM "student"
LEFT OUTER JOIN "school" "student__school" ON "student__school"."id"="student"."school_id" 
WHERE "student__school"."id"=2048

I did some digging, and the querybuilder seems to be the issue here, hence me opening an issue on this repo. This also relates to this issue on the main repo tortoise/tortoise-orm#1081

Enums not quoted

The original pypika has the bug kayak/pypika#560 which was fixed in kayak/pypika#576. pypika-tortoise has the same bug.

import asyncio
from tortoise import fields, Tortoise, Model
from enum import Enum

class MyModel(Model):
    name = fields.TextField()

class MyEnum(str, Enum):
    A = "a"

async def do():
    await Tortoise.init(db_url="sqlite://:memory:", modules={"models": ["__main__"]})
    qs = MyModel.filter(name=MyEnum.A)
    qs._make_query()
    print(qs.query)
    # expected   SELECT "id","name" FROM "mymodel" WHERE "name"='a'
    # actual     SELECT "id","name" FROM "mymodel" WHERE "name"=a

asyncio.run(do())

ImportError when pypika is also installed

When pypika and pypika-tortoise are both installed, both are installed within the same site-packages directory (see #5). This causes an ImportError, because dialects/__init__.py is imported by upstream pypika's __init__.py, instead of its own dialects.py:

File "/myproject/.venv/lib/python3.10/site-packages/tortoise/__init__.py", line 11, <module>
from pypika import Table
File "/myproject/.venv/lib/python3.10/site-packages/pypika/__init__.py", line 34, <module>
from pypika.dialects import (

dialects: <module 'pypika.dialects' from '/myproject/.venv/lib/python3.10/site-packages/pypika/dialects/__init__.py'>

ImportError:
cannot import name 'ClickHouseQuery' from 'pypika.dialects' (/myproject/.venv/lib/python3.10/site-packages/pypika/dialects/__init__.py)

Please rename this package.

And if you've watched "the Fly", you'll know the disastrous consequences of merging two species πŸ˜‰ .

Rename library

Since this library is an incompatible fork of pypika it would be good if the package directory, which is currently called pypika, would be renamed. Otherwise the original pypika and tortoise-orm conflict when installed into the same environment. Even better would be a namespace package in which this pypika fork lives under the tortoise namespace, since – realistically – it won’t be used by anyone else anyway.

Update release

Hello.
Can you please update release tag? There are already many new commits in main.
And in TortoiseORM use it's package version, not git version like pypika-tortoise = { git = "https://github.com/tortoise/pypika-tortoise.git", branch = "main" } (in pyproject.toml), because it's inconvenient to pull from git. For example, in corporate use that can be a problem.

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.