-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TableColumn and __lt__, __le__, __eq__, __ne__, __gt__, __ge__ by r/sandmasterflash_ #15
Comments
Hello, What class variables and methods should have Here is my approach/solution to class SQLite3xColumn:
def __init__(self, name,type="???"):
self.name = name
self.type = type
def __lt__(self, value):
return f"({self.name}<{value})"
# return (self.name, "<", value)
def __le__(self, value):
return f"({self.name}<={value})"
# return (self.name, "<=", value)
def __eq__(self, value):
return f"({self.name}={value})"
# return (self.name, "=", value)
def __ne__(self, value):
return f"({self.name}<>{value})"
# return (self.name, "<>", value)
def __gt__(self, value):
return f"({self.name}>{value})"
# return (self.name, ">", value)
def __ge__(self, value):
return f"({self.name}>={value})"
# return (self.name, ">=", value)
@staticmethod
def and_(left,right):
# check brackets
return f"{left}AND{right}"
@staticmethod
def or_(left,right):
# check brackets
return f"{left}OR{right}"
@staticmethod
def not_(sql):
# check brackets
return f"NOT{sql}"
col = SQLite3xColumn("column")
table.select("column", col > 20, col < 30)
table.select("column", col.or_(col > 20, col < 30))
table.select("column",WHERE=[col > 20, col < 30]) Returning directly SQL might reduce/replace |
Damn, I'm lovin' it ❤️ |
I have only one question, what is it for |
I thought that maybe it could be useful for checking type of |
Well, I'm almost done. Need test it before release, so I'll release it tomorrow :) |
It's done but in a hacky way. |
- Added 2 new classes SQLiteColumn and SQLite3 SearchCondition with many cool features - New way to set WHERE Condition - New way to set SET Condition - All select-like methods got changes in args structure (critical!) - Support column names with spaces - Info files UPDATES and WARNINGS UPD - fixed issue #15 - fixed issue #23 - fixed issue #28 - Bugfix - Tests upd Co-Authored-By: Dominik <[email protected]> Co-Authored-By: dannkunt <[email protected]>
@asadafasab here is sqllex v0.1.10.2, update up to latest version. pip install sqllex -U And here an example from WARRING.md how now you can use this new featuresWHERENow you can set users = db['users']
users.select(
SELECT=users['name'],
WHERE=( users['id'] == 2 )
)
# OR (the same)
users.select(
'name',
users['id'] == 2
) EXAMPLEfrom sqllex import SQLite3x, INTEGER, TEXT, ALL
db = SQLite3x(path='test.db')
db.create_table(
'users',
{
'id': INTEGER,
'name': TEXT
}
)
users = db['users'] # Get table from database as object
urs_id = users['id'] # Get table from database as object
usr_name = users['name'] # Get another column from table as object
print(users.columns_names) # ['id', 'name']
users.insert([1, 'Alex'])
users.insert([2, 'Blex'])
users.select(ALL, (urs_id == 2) | (urs_id == 1)) # [[1, 'Alex'], [2, 'Blex']]
users.update(
{'name': "XXXX"},
WHERE=urs_id == 1
)
users.select(
[usr_name, urs_id],
WHERE=(
(urs_id != 0) & (urs_id != 1)
)
) # [['Blex', 2]]
users.update(
{
urs_id: urs_id + 2
},
WHERE=usr_name == 'XXXX'
)
users.select([usr_name, urs_id], WHERE=(urs_id == 3)) # [['XXXX', 3]] |
I don't know why but it doesn't works with (urs_id != 0) & (urs_id != 1) # works great
(urs_id = 0) | (urs_id = 1) # works great (urs_id != 0) and (urs_id != 1) # returns bullshit - "urs_id <> 0"
(urs_id = 0) or (urs_id = 1) # returns bullshit - "urs_id = 1" I'll open an issue about whit bug, but it's not really critical and necessary. |
Yes, |
r/sandmasterflash_
This actually seems pretty cool. And in a lot feels my intuitive. I think a for awkward parts of the syntax that could be improved are how comparison operators are entered as string tokens rather than a constant, like GT, LT, something like that, that also applies to the order by syntax where you enter DESC as a string inside the order by clause, I think a constant would be better there as well.
r/v1a0
Hey r/sandmasterflash_, yeah i totally agree with you. I'll definitely add new constants like DESC, LONG and other SQLite syntax-supportive things. And even it might be reasonable to open an issue on github for add new constants requests.
But by now I have no any ideas how to enter comparison operators not as string tokens. I don't think there exist any possible way to make it work like this:
UPD:
If only code it like this
and add TableColumn class methods gt, lt and so on... it could work!
The text was updated successfully, but these errors were encountered: