v1a0 / sqllex

The most pythonic ORM (for SQLite and PostgreSQL). Seriously, try it out!
https://v1a0.github.io/sqllex
GNU General Public License v3.0
91 stars 8 forks source link

README updated to reflect the added AUTOINCREMENT type #20

Open ethixkr opened 3 years ago

ethixkr commented 3 years ago

A more conventional way of handling databases. Might confuse some people if the README continues to add primary IDs manually.

v1a0 commented 3 years ago

Hay @ethixkr, thanks for your pull request.

I'm sorry, but code from updated example failing.

Traceback (most recent call last):
  File "test_readme.py", line 15, in <module>
    db.create_table( 'groups'
...
sqlite3.OperationalError: near "AUTOINCREMENT": syntax error

The reason of this issue is column can't be AUTOINCREMENT and UNIQUE at the same time (don't ask me why, it's all apout SQL syntax)

Next fail will be in

groups.insert("User")

It's happening because sqllex sanding database 2 requests, first one:

INSERT INTO groups VALUES 'User'

and it's failed because INSERT VALUES awaiting 2 values. So it's truing create the second one request, sqllex trying insert your value in the first column (due to you don't specified in which column in table inserting this data):

INSERT INTO groups (id) VALUES 'User'

So only one way to code it another way:

groups.insert([None, "User"])

groups.insert(None, 'Guest')

But I'm one sure is this more conventional way. First "None" argument mean you insert nothing in first column.

It passed groups.insert(name="Admin") because in this case you specify for which column this value is.

To see which SQL-scripts executing you can turn on debug mode.

from sqllex.debug import debug_mode

debug_mode(True)

So now I can't merge this pull request. But don't be shy create a new one, when you'll fix this issue :)

P.S.: Hm, actually I agree, it might be confusing... But don't you think that additional "None" argument in all inserts will be look kind of strange?