Pegase745 / sqlalchemy-datatables

SQLAlchemy integration of jQuery DataTables >= 1.10.x (Pyramid and Flask examples)
MIT License
159 stars 67 forks source link

Revise api #67

Closed tdamsma closed 7 years ago

tdamsma commented 7 years ago

As discussed here

The main idea is that instead of passing an sqla_object, query, and columns, only pass the query and the columns. And instead of passing the columns by name, one can pass any SQLAlchemy column like expression, like func.upper(User.name).

An example:

Without datatables, a query can look like this:

query = self.session.query(
        User.id,
        User.name,
        User.birthday,
        func.date_part('year', func.age(User.birthday)),
    ).filter(User.id > 10)

result = query.all()

Currently, with sqlalchemy datatables there is no way to calculate the age on the fly using sql statements. In my implementation, you have to split the query and the columns and pass those to DataTables:

query = self.session.query().filter(User.id > 10)
columns = [
        ColumnDT(User.id),
        ColumnDT(User.name),
        ColumnDT(User.birthday),
        ColumnDT(func.date_part('year', func.age(User.birthday))),
        ]
rowTable = DataTables(request, query, columns)        

If you check the code, you can see it is much cleaner, as dealing with joins, properties etc are made by sqlachemy. The result of the query is determined operating on the sqlalchemy expressions.

TODO:

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-16.8%) to 70.37% when pulling fc18edde02a1c8c1dc499a12256647a8ebb1a88b on tdamsma:revise-api into 096ace624a3ca68f2d4aad6721547777ed38a98e on Pegase745:master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-16.8%) to 70.37% when pulling fc18edde02a1c8c1dc499a12256647a8ebb1a88b on tdamsma:revise-api into 096ace624a3ca68f2d4aad6721547777ed38a98e on Pegase745:master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-16.8%) to 70.37% when pulling 81377579be9377fdd276215ef2b48466f39b4c13 on tdamsma:revise-api into 096ace624a3ca68f2d4aad6721547777ed38a98e on Pegase745:master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-9.4%) to 77.714% when pulling fe0b85cefaef2338f2445921f714cb1d8832548e on tdamsma:revise-api into 096ace624a3ca68f2d4aad6721547777ed38a98e on Pegase745:master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-9.4%) to 77.714% when pulling fe0b85cefaef2338f2445921f714cb1d8832548e on tdamsma:revise-api into 096ace624a3ca68f2d4aad6721547777ed38a98e on Pegase745:master.

sewashinobi commented 7 years ago

As this became active again, there are few open issues and pull request which can be also looked right away. The one which I encountered were in regex/search while throws exception when seared for integer as the replace method don't exist

coveralls commented 7 years ago

Coverage Status

Coverage increased (+2.6%) to 89.773% when pulling 34cac09de518e3be51a7338ad95c348e9a7dbc33 on tdamsma:revise-api into 096ace624a3ca68f2d4aad6721547777ed38a98e on Pegase745:master.

coveralls commented 7 years ago

Coverage Status

Coverage increased (+2.6%) to 89.773% when pulling 34cac09de518e3be51a7338ad95c348e9a7dbc33 on tdamsma:revise-api into 096ace624a3ca68f2d4aad6721547777ed38a98e on Pegase745:master.

coveralls commented 7 years ago

Coverage Status

Coverage increased (+2.6%) to 89.773% when pulling c1329f0400b3b6b8c59efc6962d25b59429a300d on tdamsma:revise-api into 096ace624a3ca68f2d4aad6721547777ed38a98e on Pegase745:master.

coveralls commented 7 years ago

Coverage Status

Coverage increased (+2.6%) to 89.773% when pulling c1329f0400b3b6b8c59efc6962d25b59429a300d on tdamsma:revise-api into 096ace624a3ca68f2d4aad6721547777ed38a98e on Pegase745:master.

tdamsma commented 7 years ago

@devcorn, could you add some tests to illustrate the issue? I already put in code to cast values to string before doing a global search. For per column searches, using regexes on numerical values just feels wrong. I added a search_method='numeric' option which allows for searches as >=10 to return values greater than or equal to 10.

Alternatively, you can use the yadcf plugin in combination with search_method='yadcf_range_number_slider' to provide sliders for searching numerical data.

coveralls commented 7 years ago

Coverage Status

Coverage increased (+4.1%) to 91.257% when pulling 0f337c8a90c1a8fd83843854530b9f63e71f623f on tdamsma:revise-api into 096ace624a3ca68f2d4aad6721547777ed38a98e on Pegase745:master.

coveralls commented 7 years ago

Coverage Status

Coverage increased (+4.1%) to 91.257% when pulling 0f337c8a90c1a8fd83843854530b9f63e71f623f on tdamsma:revise-api into 096ace624a3ca68f2d4aad6721547777ed38a98e on Pegase745:master.

coveralls commented 7 years ago

Coverage Status

Coverage increased (+4.1%) to 91.257% when pulling 9e00b10c350b1e86c0d272b63c1900df934fa85d on tdamsma:revise-api into 096ace624a3ca68f2d4aad6721547777ed38a98e on Pegase745:master.

coveralls commented 7 years ago

Coverage Status

Coverage increased (+4.1%) to 91.257% when pulling 9e00b10c350b1e86c0d272b63c1900df934fa85d on tdamsma:revise-api into 096ace624a3ca68f2d4aad6721547777ed38a98e on Pegase745:master.

coveralls commented 7 years ago

Coverage Status

Coverage increased (+4.1%) to 91.257% when pulling 9e00b10c350b1e86c0d272b63c1900df934fa85d on tdamsma:revise-api into 096ace624a3ca68f2d4aad6721547777ed38a98e on Pegase745:master.

coveralls commented 7 years ago

Coverage Status

Coverage increased (+4.1%) to 91.257% when pulling 69e00f12fd3833b6d1992031eea0757debc6f2fb on tdamsma:revise-api into 096ace624a3ca68f2d4aad6721547777ed38a98e on Pegase745:master.

tdamsma commented 7 years ago

@Pegase745 Even though there are some todo's left, I think the PR is ready to be merged. Perhaps you can have look

Pegase745 commented 7 years ago

@tdamsma Great job indeed. I'll take a deeper look tonight if you won't mind and merge the whole thing :+1:

Pegase745 commented 7 years ago

@tdamsma done. Could you just update the README's example or at least an example here if you have the time please ?