Giter Club home page Giter Club logo

sort-string-to-sql's Introduction

Sort-String-To-SQL

Sort String To SQL For Python 📝

參考 sortStringToSql 修改為 Python 版本

說明

將 'sort expressions' 轉換成 SQL expressions,方便資料庫 ORDER BY 欄位, E.g. +id 會被轉換為 id ASC

因為我目前使用 MySQL 居多,所以不同資料庫寫法可能有稍微不同,請在自行修改或 Issuse 給我 😄

範例

可參考 sort_string_to_sql.py

print('+id ->', sort_str_to_sql(sort_expression='+id'))
## +id -> id ASC

print('+id,-name ->', sort_str_to_sql(sort_expression='+id,-name'))
## +id,-name -> id ASC, name DESC

print(' ->', sort_str_to_sql(sort_expression=''))
##   ->

更多範例可參考 tests.py

Test By Case

目前是 by case 寫測試,可參考 tests.py

請在命令提示字元 ( cmd ) 底下輸入

 python -m unittest -v tests

output

test_case_1 (tests.TestCase) ... ok
test_case_2 (tests.TestCase) ... ok
test_case_3 (tests.TestCase) ... ok
test_case_4 (tests.TestCase) ... ok
test_case_5 (tests.TestCase) ... ok
test_case_6 (tests.TestCase) ... ok
test_case_7 (tests.TestCase) ... ok
test_case_8 (tests.TestCase) ... ok
test_case_9 (tests.TestCase) ... ok

----------------------------------------------------------------------
Ran 9 tests in 0.001s

OK

執行環境

  • Python 3.6.2

Reference

License

MIT license

sort-string-to-sql's People

Contributors

twtrubiks avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.