├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── dependabot.yml └── workflows │ └── nuget.yml ├── .gitignore ├── .vscode ├── launch.json └── tasks.json ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── RestSQL.NPoco.Tests ├── RestSQL.NPoco.Tests.csproj └── UnitTest1.cs ├── RestSQL.NPoco ├── NPocoBuilder.cs ├── NPocoExpression.cs ├── NPocoExtensions.cs └── RestSQL.NPoco.csproj ├── RestSQL.SqlKata.Tests ├── RestSQL.SqlKata.Tests.csproj └── UnitTest1.cs ├── RestSQL.SqlKata ├── IColumnNameTransform.cs ├── RestSQL.SqlKata.csproj └── SqlKataBuilder.cs ├── RestSQL.Tests ├── ParseTests.cs ├── Providers │ ├── TestExpression.cs │ └── TestExpressionBuilder.cs └── RestSQL.Tests.csproj ├── RestSQL.sln └── RestSQL ├── IExpressionBuilder.cs ├── RestSQL.cs ├── RestSQL.csproj ├── RsqlExpressionVisitor.cs ├── RsqlLexer.g4 ├── RsqlLexer.g4.cs ├── RsqlParser.g4 ├── RsqlParser.g4.cs └── RsqlQueryType.cs /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[BUG] " 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 16 | **Expected behavior** 17 | A clear and concise description of what you expected to happen. 18 | 19 | **Actual behavior** 20 | If applicable, add some examples to help explain your problem. 21 | 22 | **Additional context** 23 | Add any other context about the problem here. 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "nuget" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "daily" 12 | -------------------------------------------------------------------------------- /.github/workflows/nuget.yml: -------------------------------------------------------------------------------- 1 | name: Publish Packages - RestSQL 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v2 13 | - name: Setup .NET Core 14 | uses: actions/setup-dotnet@v1 15 | with: 16 | dotnet-version: 3.1.101 17 | - name: Install dependencies 18 | run: dotnet restore 19 | - name: Build 20 | run: dotnet build --configuration Release --no-restore 21 | - name: Publish RestSQL 22 | uses: brandedoutcast/publish-nuget@v2.5.2 23 | with: 24 | PROJECT_FILE_PATH: RestSQL/RestSQL.csproj 25 | NUGET_KEY: ${{secrets.NUGET_API_KEY}} 26 | - name: Publish RestSQL.NPoco 27 | uses: brandedoutcast/publish-nuget@v2.5.2 28 | with: 29 | PROJECT_FILE_PATH: RestSQL.NPoco/RestSQL.NPoco.csproj 30 | NUGET_KEY: ${{secrets.NUGET_API_KEY}} 31 | - name: Publish RestSQL.SqlKata 32 | uses: brandedoutcast/publish-nuget@v2.5.2 33 | with: 34 | PROJECT_FILE_PATH: RestSQL.SqlKata/RestSQL.SqlKata.csproj 35 | NUGET_KEY: ${{secrets.NUGET_API_KEY}} 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to find out which attributes exist for C# debugging 3 | // Use hover for the description of the existing attributes 4 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": ".NET Core Launch (console)", 9 | "type": "coreclr", 10 | "request": "launch", 11 | "preLaunchTask": "build", 12 | // If you have changed target frameworks, make sure to update the program path. 13 | "program": "${workspaceFolder}/RestSQL.SqlKata.Tests/bin/Debug/netcoreapp2.2/RestSQL.SqlKata.Tests.dll", 14 | "args": [], 15 | "cwd": "${workspaceFolder}/RestSQL.SqlKata.Tests", 16 | // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window 17 | "console": "internalConsole", 18 | "stopAtEntry": false, 19 | "internalConsoleOptions": "openOnSessionStart" 20 | }, 21 | { 22 | "name": ".NET Core Attach", 23 | "type": "coreclr", 24 | "request": "attach", 25 | "processId": "${command:pickProcess}" 26 | } 27 | ,] 28 | } -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "command": "dotnet", 7 | "type": "process", 8 | "args": [ 9 | "build", 10 | "${workspaceFolder}/RestSQL.SqlKata.Tests/RestSQL.SqlKata.Tests.csproj" 11 | ], 12 | "problemMatcher": "$msCompile" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at iquirino91@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2019 Igor Quirino 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RestSQL 2 | 3 | Port of: https://github.com/mmrath/rsql-parser 4 | 5 | C# Sql Where Clause Parser to be used as Rest Parameters to filter data 6 | 7 | This parser is strong using Visitor Pattern: 8 | The IExpressionBuilder should be implemented and then call to build: 9 | 10 | RestSQL.Parse(query, this); 11 | 12 | You can base on our test to implement your own strategy: 13 | 14 | var testExpressionBuilder = new TestExpressionBuilder(); 15 | testExpressionBuilder.Build("ab > 'DE' and (c = d or d > 4.3) and e>4 or rere in (20,30,40,50) and defer between 2 and 3 or rerer not in ('432','234324')"); 16 | 17 | Nuget Package: https://www.nuget.org/packages/RestSQL/ 18 | 19 | Implemented strategies: 20 | 21 | - SqlKata.QueryBuilder 22 | 23 | https://www.nuget.org/packages/RestSQL.SqlKata/ 24 | 25 | var t = new Query().From("tblLalala").Where("Name", "Igor").Where(c=>c.Where("status","1").OrWhere("status","2")); 26 | 27 | var compiler = new Oracle11gCompiler(); 28 | var testExpressionBuilder = new SqlKataBuilder(); 29 | 30 | var q = testExpressionBuilder.Build("ab > 'DE' and (c = d or d > 4.3) and e>4 or rere in (20,30,40,50) and defer between 2 and 3 or rerer not in ('432','234324')"); 31 | 32 | var qb = testExpressionBuilder.BuildFrom("ab > 'DE' and (c = d or d > 4.3) and e>4 or rere in (20,30,40,50) and defer between 2 and 3 or rerer not in ('432','234324')", t); 33 | 34 | var sql = compiler.Compile(q.From("MyTable")); 35 | var sqlb = compiler.Compile(qb); 36 | 37 | - NPoco 38 | 39 | https://www.nuget.org/packages/RestSQL.NPoco/ 40 | 41 | var s = new SqlBuilder(); 42 | s.Where("ab > 'DE' and (c = d or d > 4.3) and e>4 or rere in (20,30,40,50) and defer between 2 and 3 or rerer not in ('432','234324')"); 43 | 44 | var db = new Database("conn"); 45 | db.Fetch(template); 46 | -------------------------------------------------------------------------------- /RestSQL.NPoco.Tests/RestSQL.NPoco.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | false 7 | 8 | wareboss.com 9 | 10 | 1.0.8 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /RestSQL.NPoco.Tests/UnitTest1.cs: -------------------------------------------------------------------------------- 1 | using NPoco; 2 | using System; 3 | using Xunit; 4 | 5 | namespace RestSQL.NPoco.Tests 6 | { 7 | public class UnitTest1 8 | { 9 | [Fact] 10 | public void Test1() 11 | { 12 | var testExpressionBuilder = new NPocoBuilder(); 13 | 14 | var q = testExpressionBuilder.Build("ab > 'DE' and (c = d or d > 4.3) and e>4 or rere in (20,30,40,50) and defer between 2 and 3 or rerer not in ('432','234324')"); 15 | 16 | Assert.Equal("ab > @0 AND ( c = @1 OR d > @2 ) AND e > @3 OR rere IN (@4,@5,@6,@7) AND defer BETWEEN @8 AND @9 OR rerer NOT IN (@10,@11)", q.Sql); 17 | Assert.Equal("DE, d, 4.3, 4, 20, 30, 40, 50, 2, 3, 432, 234324", string.Join(", ", q.Params)); 18 | 19 | var s = new SqlBuilder(); 20 | s.Where("ab > 'DE' and (c = d or d > 4.3) and e>4 or rere in (20,30,40,50) and defer between 2 and 3 or rerer not in ('432','234324')"); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /RestSQL.NPoco/NPocoBuilder.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text; 3 | 4 | namespace RestSQL.NPoco 5 | { 6 | public class NPocoBuilder : IExpressionBuilder 7 | { 8 | //TODO: Change Parameters "?" with @0, @1, @2, ... 9 | //https://github.com/schotime/NPoco/wiki/Sql-Templating 10 | private static readonly string OR = " OR "; 11 | private static readonly string AND = " AND "; 12 | private static readonly string COMPARE_TEMPLATE = "{0} {1} ?"; 13 | private static readonly string IS_NULL_TEMPLATE = "{0} IS NULL"; 14 | private static readonly string IS_NOT_NULL_TEMPLATE = "{0} IN NOT NULL"; 15 | private static readonly string LIKE_TEMPLATE = string.Format(COMPARE_TEMPLATE, "{0}", "LIKE"); 16 | private static readonly string NOT_LIKE_TEMPLATE = string.Format(COMPARE_TEMPLATE, "{0}", "NOT LIKE"); 17 | private static readonly string BETWEEN_TEMPLATE = "{0} BETWEEN ? AND ?"; 18 | private static readonly string NOT_BETWEEN_TEMPLATE = "{0} NOT BETWEEN ? AND ?"; 19 | private static readonly string IN_TEMPLATE = "{0} IN"; 20 | private static readonly string NOT_IN_TEMPLATE = "{0} NOT IN"; 21 | private static readonly string COMMA = ","; 22 | 23 | public delegate string ColumnNameEventHandler(string columnName); 24 | public event ColumnNameEventHandler OnColumnName; 25 | 26 | public NPocoExpression Or(NPocoExpression statement1, NPocoExpression statement2) 27 | { 28 | return this.AndOr(statement1, statement2, OR); 29 | } 30 | 31 | public NPocoExpression And(NPocoExpression statement1, NPocoExpression statement2) 32 | { 33 | return this.AndOr(statement1, statement2, AND); 34 | } 35 | 36 | public NPocoExpression Parenthesize(NPocoExpression statement) 37 | { 38 | return new NPocoExpression(" ( " + statement.rawSql + " ) ", statement.parameters); 39 | } 40 | 41 | private NPocoExpression AndOr(NPocoExpression statement1, NPocoExpression statement2, string op) 42 | { 43 | if (statement1 == null) 44 | return statement2; 45 | if (statement2 == null) 46 | return statement1; 47 | 48 | string whereSql = statement1.rawSql + op + statement2.rawSql; 49 | 50 | var p = new List(); 51 | p.AddRange(statement1.parameters); 52 | p.AddRange(statement2.parameters); 53 | 54 | return new NPocoExpression(whereSql, p); 55 | } 56 | 57 | public NPocoExpression Equal(string columnCode, object value) 58 | { 59 | return this.ComparePredicate(columnCode, "=", value); 60 | } 61 | 62 | public NPocoExpression NotEqual(string columnCode, object value) 63 | { 64 | return this.ComparePredicate(columnCode, "!=", value); 65 | } 66 | 67 | public NPocoExpression LessOrEqual(string columnCode, object value) 68 | { 69 | return this.ComparePredicate(columnCode, "<=", value); 70 | } 71 | 72 | public NPocoExpression LessThan(string columnCode, object value) 73 | { 74 | return this.ComparePredicate(columnCode, "<", value); 75 | } 76 | 77 | public NPocoExpression GreaterOrEqual(string columnCode, object value) 78 | { 79 | return this.ComparePredicate(columnCode, ">=", value); 80 | } 81 | 82 | public NPocoExpression GreaterThan(string columnCode, object value) 83 | { 84 | return this.ComparePredicate(columnCode, ">", value); 85 | } 86 | 87 | public NPocoExpression IsNotNull(string column) 88 | { 89 | return new NPocoExpression(string.Format(IS_NOT_NULL_TEMPLATE, this.GetColumnName(column))); 90 | } 91 | 92 | public NPocoExpression IsNull(string column) 93 | { 94 | return new NPocoExpression(string.Format(IS_NULL_TEMPLATE, this.GetColumnName(column))); 95 | } 96 | 97 | public NPocoExpression NotLike(string column, object value) 98 | { 99 | return new NPocoExpression(string.Format(NOT_LIKE_TEMPLATE, this.GetColumnName(column)), value); 100 | } 101 | 102 | public NPocoExpression Like(string column, object value) 103 | { 104 | return new NPocoExpression(string.Format(LIKE_TEMPLATE, this.GetColumnName(column)), value); 105 | } 106 | 107 | public NPocoExpression NotBetween(string column, object start, object end) 108 | { 109 | return new NPocoExpression(string.Format(NOT_BETWEEN_TEMPLATE, this.GetColumnName(column)), start, end); 110 | } 111 | 112 | public NPocoExpression Between(string column, object start, object end) 113 | { 114 | return new NPocoExpression(string.Format(BETWEEN_TEMPLATE, this.GetColumnName(column)), start, end); 115 | } 116 | 117 | public NPocoExpression NotIn(string column, List values) 118 | { 119 | 120 | var inClause = new StringBuilder(string.Format(NOT_IN_TEMPLATE, this.GetColumnName(column))); 121 | inClause.Append(" ("); 122 | inClause.Append(this.Repeat("?", COMMA, values.Count)); 123 | inClause.Append(")"); 124 | 125 | return new NPocoExpression(inClause.ToString(), values); 126 | } 127 | 128 | public NPocoExpression In(string column, List values) 129 | { 130 | var inClause = new StringBuilder(string.Format(IN_TEMPLATE, this.GetColumnName(column))); 131 | inClause.Append(" ("); 132 | inClause.Append(this.Repeat("?", COMMA, values.Count)); 133 | inClause.Append(")"); 134 | 135 | return new NPocoExpression(inClause.ToString(), values); 136 | } 137 | 138 | private NPocoExpression ComparePredicate(string columnCode, string op, object value) 139 | { 140 | var p = new List { value }; 141 | return new NPocoExpression(string.Format(COMPARE_TEMPLATE, this.GetColumnName(columnCode), op), p); 142 | } 143 | 144 | private string GetColumnName(string columnName) 145 | { 146 | string cName = null; 147 | 148 | if (OnColumnName != null) 149 | cName = OnColumnName(columnName); 150 | 151 | if (string.IsNullOrWhiteSpace(cName)) 152 | return columnName; 153 | 154 | return cName; 155 | } 156 | 157 | private string Repeat(string s, string separator, int count) 158 | { 159 | var str = new StringBuilder((s.Length + separator.Length) * count); 160 | while (--count > 0) 161 | str.Append(s).Append(separator); 162 | 163 | return str.Append(s).ToString(); 164 | } 165 | 166 | public NPocoExpression Build(string query) 167 | { 168 | return RestSQL.Parse(query, this); 169 | } 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /RestSQL.NPoco/NPocoExpression.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System.Text; 4 | 5 | namespace RestSQL.NPoco 6 | { 7 | public class NPocoExpression 8 | { 9 | internal string rawSql; 10 | internal IReadOnlyCollection parameters; 11 | 12 | public IReadOnlyCollection Params 13 | { 14 | get 15 | { 16 | if (this.parameters == null || this.parameters.Count <= 0) 17 | return this.parameters; 18 | 19 | return this.DoFlatParams(this.parameters).AsReadOnly(); 20 | } 21 | } 22 | 23 | public string Sql 24 | { 25 | get 26 | { 27 | var fParams = this.Params; 28 | string[] rSql = this.rawSql.Split('?'); 29 | 30 | var sbSql = new StringBuilder(); 31 | 32 | for (int i = 0; i < rSql.Length; i++) 33 | { 34 | sbSql.Append(rSql[i]); 35 | if (i < fParams.Count) 36 | sbSql.Append($"@{i}"); 37 | } 38 | 39 | return sbSql.ToString(); 40 | } 41 | } 42 | 43 | private List DoFlatParams(IEnumerable items) 44 | { 45 | var ret = new List(); 46 | foreach (object inner in items) 47 | { 48 | if (inner is IReadOnlyCollection col) 49 | ret.AddRange(this.DoFlatParams(col)); 50 | else 51 | ret.Add(inner); 52 | } 53 | return ret; 54 | } 55 | 56 | public NPocoExpression(string whereClause, List parameters) 57 | { 58 | this.rawSql = whereClause; 59 | this.parameters = parameters.AsReadOnly(); 60 | } 61 | 62 | public NPocoExpression(string whereClause, params object[] parameters) : this(whereClause, parameters?.ToList()) 63 | { 64 | } 65 | 66 | public override string ToString() 67 | { 68 | return "NPocoExpression {" + " where = '" + this.rawSql + '\'' + ", params = [" + string.Join(", ", this.parameters.ToArray()) + "]}"; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /RestSQL.NPoco/NPocoExtensions.cs: -------------------------------------------------------------------------------- 1 | using RestSQL.NPoco; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace NPoco 8 | { 9 | public static class NPocoExtensions 10 | { 11 | public static SqlBuilder Where(this SqlBuilder sql, string where) 12 | { 13 | var builder = new NPocoBuilder(); 14 | var expression = builder.Build(where); 15 | return sql.Where(expression.Sql, expression.Params.ToArray()); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /RestSQL.NPoco/RestSQL.NPoco.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.1 5 | true 6 | Igor Quirino 7 | wareboss.com 8 | NPoco QueryBuilder implementation for RestSQL 9 | Copyright 2020 Igor Quirino (wareboss.com) 10 | https://raw.githubusercontent.com/iquirino/RestSQL/master/LICENSE 11 | https://github.com/iquirino/RestSQL 12 | https://github.com/iquirino/RestSQL 13 | SQL, SQL PARSER, QUERY BUILDER, NPOCO, RESTSQL, REST 14 | 1.0.10 15 | README.md 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /RestSQL.SqlKata.Tests/RestSQL.SqlKata.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | false 7 | 8 | wareboss.com 9 | 10 | 1.0.8 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /RestSQL.SqlKata.Tests/UnitTest1.cs: -------------------------------------------------------------------------------- 1 | using SqlKata; 2 | using SqlKata.Compilers; 3 | using Xunit; 4 | 5 | namespace RestSQL.SqlKata.Tests 6 | { 7 | public class UnitTest1 8 | { 9 | [Fact] 10 | public void Test1() 11 | { 12 | var t = new Query().From("tblLalala").Where("Name", "Igor").Where(c => c.Where("status", "1").OrWhere("status", "2")); 13 | 14 | var compiler = new OracleCompiler(); 15 | compiler.UseLegacyPagination = true; 16 | var testExpressionBuilder = new SqlKataBuilder(); 17 | 18 | //testExpressionBuilder.OnColumnName += cname => cname + "_C"; 19 | 20 | var q = testExpressionBuilder.Build("ab > 'DE' and (c = d or d > 4.3) and e>4 or rere in (20,30,40,50) and defer between 2 and 3 or rerer not in ('432','234324')"); 21 | 22 | var qb = testExpressionBuilder.BuildFrom("ab > 'DE' and (c = d or d > 4.3) and e>4 or rere in (20,30,40,50) and defer between 2 and 3 or rerer not in ('432','234324')", t); 23 | 24 | var sql = compiler.Compile(q.From("MyTable")); 25 | var sqlb = compiler.Compile(qb); 26 | 27 | Assert.Equal("SELECT * FROM \"MyTable\" WHERE \"ab\" > ? AND (\"c\" = ? OR \"d\" > ?) AND \"e\" > ? OR \"rere\" IN (?, ?, ?, ?) OR \"defer\" BETWEEN ? AND ? OR \"rerer\" NOT IN (?, ?)", sql.RawSql); 28 | Assert.Equal("SELECT * FROM \"tblLalala\" WHERE \"Name\" = ? AND (\"status\" = ? OR \"status\" = ?) AND (\"ab\" > ? AND (\"c\" = ? OR \"d\" > ?) AND \"e\" > ? OR \"rere\" IN (?, ?, ?, ?) OR \"defer\" BETWEEN ? AND ? OR \"rerer\" NOT IN (?, ?))", sqlb.RawSql); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /RestSQL.SqlKata/IColumnNameTransform.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace RestSQL.SqlKata 6 | { 7 | public interface IColumnNameTransform 8 | { 9 | string Transform(string columnName); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /RestSQL.SqlKata/RestSQL.SqlKata.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.1 5 | true 6 | Igor Quirino 7 | wareboss.com 8 | https://github.com/iquirino/RestSQL 9 | SqlKata QueryBuilder implementation for RestSQL 10 | https://github.com/iquirino/RestSQL 11 | SQL, SQL PARSER, QUERY BUILDER, SQLKATA, RESTSQL, REST 12 | Copyright 2020 Igor Quirino (wareboss.com) 13 | https://raw.githubusercontent.com/iquirino/RestSQL/master/LICENSE 14 | 1.0.10.0 15 | 1.0.10.0 16 | 1.0.10 17 | README.md 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /RestSQL.SqlKata/SqlKataBuilder.cs: -------------------------------------------------------------------------------- 1 | using SqlKata; 2 | using System.Collections.Generic; 3 | 4 | namespace RestSQL.SqlKata 5 | { 6 | public class SqlKataBuilder : IExpressionBuilder 7 | { 8 | private readonly IColumnNameTransform transform = null; 9 | 10 | public delegate string ColumnNameEventHandler(string columnName); 11 | public event ColumnNameEventHandler OnColumnName; 12 | 13 | public delegate bool CustomQueryEventHandler(out Query query, RSqlQueryType action, string columnName, params object[] values); 14 | public event CustomQueryEventHandler CustomQuery; 15 | 16 | public SqlKataBuilder(IColumnNameTransform transform = null) 17 | { 18 | if (transform != null) 19 | this.transform = transform; 20 | } 21 | 22 | public Query And(Query expression1, Query expression2) 23 | { 24 | if (expression1 == null) 25 | return expression2; 26 | if (expression2 == null) 27 | return expression1; 28 | 29 | foreach (var expClauses in expression2.Clauses) 30 | { 31 | if (expClauses is AbstractCondition exp) 32 | exp.IsOr = false; 33 | } 34 | 35 | expression1.Clauses.AddRange(expression2.Clauses); 36 | return expression1; 37 | } 38 | 39 | public Query Or(Query expression1, Query expression2) 40 | { 41 | if (expression1 == null) 42 | return expression2; 43 | if (expression2 == null) 44 | return expression1; 45 | 46 | foreach (var expClauses in expression2.Clauses) 47 | { 48 | if (expClauses is AbstractCondition exp) 49 | exp.IsOr = true; 50 | } 51 | 52 | expression1.Clauses.AddRange(expression2.Clauses); 53 | 54 | return expression1; 55 | } 56 | 57 | public Query Parenthesize(Query expression) 58 | { 59 | var nested = new NestedCondition 60 | { 61 | Component = "where", 62 | Query = new Query() 63 | }; 64 | nested.Query.Clauses.AddRange(expression.Clauses); 65 | 66 | var q = new Query(); 67 | q.Clauses.Add(nested); 68 | 69 | return q; 70 | } 71 | 72 | public Query Between(string column, object start, object end) 73 | { 74 | if (CustomQuery != null && CustomQuery(out Query query, RSqlQueryType.Between, column, start, end)) 75 | return query; 76 | 77 | return new Query().WhereBetween(GetColumnName(column), start, end); 78 | } 79 | 80 | public Query Equal(string column, object value) 81 | { 82 | if (CustomQuery != null && CustomQuery(out Query query, RSqlQueryType.Equal, column, value)) 83 | return query; 84 | 85 | return new Query().Where(GetColumnName(column), value); 86 | } 87 | 88 | public Query GreaterOrEqual(string column, object value) 89 | { 90 | if (CustomQuery != null && CustomQuery(out Query query, RSqlQueryType.GreaterOrEqual, column, value)) 91 | return query; 92 | 93 | return new Query().Where(GetColumnName(column), ">=", value); 94 | } 95 | 96 | public Query GreaterThan(string column, object value) 97 | { 98 | if (CustomQuery != null && CustomQuery(out Query query, RSqlQueryType.GreatherThan, column, value)) 99 | return query; 100 | 101 | return new Query().Where(GetColumnName(column), ">", value); 102 | } 103 | 104 | public Query In(string column, List values) 105 | { 106 | if (CustomQuery != null && CustomQuery(out Query query, RSqlQueryType.In, column, values.ToArray())) 107 | return query; 108 | 109 | return new Query().WhereIn(GetColumnName(column), values); 110 | } 111 | 112 | public Query IsNotNull(string column) 113 | { 114 | if (CustomQuery != null && CustomQuery(out Query query, RSqlQueryType.IsNotNull, column)) 115 | return query; 116 | 117 | return new Query().WhereNotNull(GetColumnName(column)); 118 | } 119 | 120 | public Query IsNull(string column) 121 | { 122 | if (CustomQuery != null && CustomQuery(out Query query, RSqlQueryType.IsNull, column)) 123 | return query; 124 | 125 | return new Query().WhereNull(GetColumnName(column)); 126 | } 127 | 128 | public Query LessOrEqual(string column, object value) 129 | { 130 | if (CustomQuery != null && CustomQuery(out Query query, RSqlQueryType.LessOrEqual, column, value)) 131 | return query; 132 | 133 | return new Query().Where(GetColumnName(column), "<=", value); 134 | } 135 | 136 | public Query LessThan(string column, object value) 137 | { 138 | if (CustomQuery != null && CustomQuery(out Query query, RSqlQueryType.LessThan, column, value)) 139 | return query; 140 | 141 | return new Query().Where(GetColumnName(column), "<", value); 142 | } 143 | 144 | public Query Like(string column, object value) 145 | { 146 | if (CustomQuery != null && CustomQuery(out Query query, RSqlQueryType.Like, column, value)) 147 | return query; 148 | 149 | return new Query().WhereLike(GetColumnName(column), value.ToString(), true); 150 | } 151 | 152 | public Query NotBetween(string column, object start, object end) 153 | { 154 | if (CustomQuery != null && CustomQuery(out Query query, RSqlQueryType.NotBetween, column, start, end)) 155 | return query; 156 | 157 | return new Query().WhereNotBetween(GetColumnName(column), start, end); 158 | } 159 | 160 | public Query NotEqual(string column, object value) 161 | { 162 | if (CustomQuery != null && CustomQuery(out Query query, RSqlQueryType.NotEqual, column, value)) 163 | return query; 164 | 165 | return new Query().Where(GetColumnName(column), "!=", value); 166 | } 167 | 168 | public Query NotIn(string column, List values) 169 | { 170 | if (CustomQuery != null && CustomQuery(out Query query, RSqlQueryType.NotIn, column, values.ToArray())) 171 | return query; 172 | 173 | return new Query().WhereNotIn(GetColumnName(column), values); 174 | } 175 | 176 | public Query NotLike(string column, object value) 177 | { 178 | if (CustomQuery != null && CustomQuery(out Query query, RSqlQueryType.NotLike, column, value)) 179 | return query; 180 | 181 | return new Query().WhereNotLike(GetColumnName(column), value.ToString(), true); 182 | } 183 | 184 | public Query Build(string query) 185 | { 186 | return RestSQL.Parse(query, this); 187 | } 188 | 189 | public Query BuildFrom(string query, Query from) 190 | { 191 | var build = this.Build(query); 192 | 193 | var nested = new NestedCondition 194 | { 195 | Component = "where", 196 | Query = new Query() 197 | }; 198 | nested.Query.Clauses.AddRange(build.Clauses); 199 | 200 | from.Clauses.Add(nested); 201 | return from; 202 | } 203 | private string GetColumnName(string columnName) 204 | { 205 | string cName = null; 206 | 207 | if (OnColumnName != null) 208 | cName = OnColumnName(columnName); 209 | 210 | if (string.IsNullOrWhiteSpace(cName) && this.transform != null) 211 | cName = this.transform.Transform(columnName); 212 | 213 | if (string.IsNullOrWhiteSpace(cName)) 214 | return columnName; 215 | 216 | return cName; 217 | } 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /RestSQL.Tests/ParseTests.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using RestQL.Tests.Providers; 3 | using System; 4 | using Xunit; 5 | 6 | namespace RestSQL.Tests 7 | { 8 | public class ParseTests 9 | { 10 | [Fact] 11 | public void Test1() 12 | { 13 | var testExpressionBuilder = new TestExpressionBuilder(); 14 | var p = RestSQL.Parse("ab > 'DE' and (c = d or d > 4.3) and e>4 or rere in (20,30,40,50) and defer between 2 and 3 or rerer not in ('432','234324')", testExpressionBuilder); 15 | //var gIgor = new FilterGroup(); 16 | //gIgor.Add(new FilterNode("igor1", ComparisonOperator.Equal, LogicalOperator.Undefined, "gato1")); 17 | //gIgor.Add(new FilterNode("igor2", ComparisonOperator.Equal, LogicalOperator.And, "gato2")); 18 | //gIgor.Add(new FilterNode("igor3", ComparisonOperator.Equal, LogicalOperator.And, "gato3")); 19 | //gIgor.Add(new FilterNode("igor4", ComparisonOperator.Equal, LogicalOperator.And, "gato4")); 20 | 21 | //var root = new FilterGroup(); 22 | //root.Add(new FilterNode("caio1", ComparisonOperator.Equal, LogicalOperator.Undefined, "faio1")); 23 | //root.Add(new FilterNode("caio2", ComparisonOperator.Equal, LogicalOperator.And, "faio2")); 24 | //root.Add(new FilterNode("caio3", ComparisonOperator.Equal, LogicalOperator.And, "faio3")); 25 | //root.Add(new FilterNode("caio4", ComparisonOperator.Equal, LogicalOperator.And, "faio4")); 26 | //root.Add(gIgor); 27 | 28 | 29 | //string json = JsonConvert.SerializeObject(root, Formatting.Indented); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /RestSQL.Tests/Providers/TestExpression.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | 4 | namespace RestQL.Tests.Providers 5 | { 6 | public class TestExpression 7 | { 8 | private readonly string whereClause; 9 | private readonly IReadOnlyCollection p; 10 | 11 | public TestExpression(string whereClause, List parameters) 12 | { 13 | this.whereClause = whereClause; 14 | this.p = parameters.AsReadOnly(); 15 | } 16 | 17 | public TestExpression(string whereClause, params object[] parameters) : this(whereClause, parameters?.ToList()) 18 | { 19 | } 20 | 21 | public override string ToString() 22 | { 23 | return "TestExpression{" + 24 | "whereClause='" + this.whereClause + '\'' + 25 | ", params=" + this.p + 26 | '}'; 27 | } 28 | 29 | public string GetWhereClause() 30 | { 31 | return this.whereClause; 32 | } 33 | 34 | public List GetParams() 35 | { 36 | return this.p.ToList(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /RestSQL.Tests/Providers/TestExpressionBuilder.cs: -------------------------------------------------------------------------------- 1 | using RestSQL; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace RestQL.Tests.Providers 6 | { 7 | public class TestExpressionBuilder : IExpressionBuilder 8 | { 9 | private static readonly string OR = " OR "; 10 | private static readonly string AND = " AND "; 11 | private static readonly string COMPARISION_TEMPLATE = "{0} {1} ?"; 12 | private static readonly string IS_NULL_TEMPLATE = "{0} IS NULL"; 13 | private static readonly string IS_NOT_NULL_TEMPLATE = "{0} IN NOT NULL"; 14 | private static readonly string LIKE_TEMPLATE = "{0} LIKE ?"; 15 | private static readonly string NOT_LIKE_TEMPLATE = "{0} NOT LIKE ?"; 16 | private static readonly string BETWEEN_TEMPLATE = "{0} BETWEEN ? AND ?"; 17 | private static readonly string NOT_BETWEEN_TEMPLATE = "{0} NOT BETWEEN ? AND ?"; 18 | private static readonly string IN_TEMPLATE = "{0} IN"; 19 | private static readonly string NOT_IN_TEMPLATE = "{0} NOT IN"; 20 | private static readonly string COMMA = ","; 21 | 22 | public TestExpression Or(TestExpression statement1, TestExpression statement2) 23 | { 24 | return this.andOr(statement1, statement2, OR); 25 | } 26 | 27 | public TestExpression And(TestExpression statement1, TestExpression statement2) 28 | { 29 | return this.andOr(statement1, statement2, AND); 30 | } 31 | 32 | public TestExpression Parenthesize(TestExpression statement) 33 | { 34 | return new TestExpression(" ( " + statement.GetWhereClause() + " ) ", statement.GetParams()); 35 | } 36 | 37 | private TestExpression andOr(TestExpression statement1, TestExpression statement2, string op) 38 | { 39 | if (statement1 == null) 40 | return statement2; 41 | if (statement2 == null) 42 | return statement1; 43 | 44 | string whereSql = statement1.GetWhereClause() + op + statement2.GetWhereClause(); 45 | 46 | var p = new List(); 47 | p.AddRange(statement1.GetParams()); 48 | p.AddRange(statement2.GetParams()); 49 | 50 | return new TestExpression(whereSql, p); 51 | } 52 | 53 | public TestExpression Equal(string columnCode, object value) 54 | { 55 | return this.comparisionPredicate(columnCode, "=", value); 56 | } 57 | 58 | public TestExpression NotEqual(string columnCode, object value) 59 | { 60 | return this.comparisionPredicate(columnCode, "!=", value); 61 | } 62 | 63 | public TestExpression LessOrEqual(string columnCode, object value) 64 | { 65 | return this.comparisionPredicate(columnCode, "<=", value); 66 | } 67 | 68 | public TestExpression LessThan(string columnCode, object value) 69 | { 70 | return this.comparisionPredicate(columnCode, "<", value); 71 | } 72 | 73 | public TestExpression GreaterOrEqual(string columnCode, object value) 74 | { 75 | return this.comparisionPredicate(columnCode, ">=", value); 76 | } 77 | 78 | public TestExpression GreaterThan(string columnCode, object value) 79 | { 80 | return this.comparisionPredicate(columnCode, ">", value); 81 | } 82 | 83 | public TestExpression IsNotNull(string column) 84 | { 85 | return new TestExpression(string.Format(IS_NOT_NULL_TEMPLATE, this.getColumnName(column))); 86 | } 87 | 88 | public TestExpression IsNull(string column) 89 | { 90 | return new TestExpression(string.Format(IS_NULL_TEMPLATE, this.getColumnName(column))); 91 | } 92 | 93 | public TestExpression NotLike(string column, object value) 94 | { 95 | return new TestExpression(string.Format(NOT_LIKE_TEMPLATE, this.getColumnName(column)), value); 96 | } 97 | 98 | public TestExpression Like(string column, object value) 99 | { 100 | return new TestExpression(string.Format(LIKE_TEMPLATE, this.getColumnName(column)), value); 101 | } 102 | 103 | public TestExpression NotBetween(string column, object start, object end) 104 | { 105 | return new TestExpression(string.Format(NOT_BETWEEN_TEMPLATE, this.getColumnName(column)), start, end); 106 | } 107 | 108 | public TestExpression Between(string column, object start, object end) 109 | { 110 | return new TestExpression(string.Format(BETWEEN_TEMPLATE, this.getColumnName(column)), start, end); 111 | } 112 | 113 | public TestExpression NotIn(string column, List values) 114 | { 115 | 116 | var inClause = new StringBuilder(string.Format(NOT_IN_TEMPLATE, this.getColumnName(column))); 117 | inClause.Append(" ("); 118 | inClause.Append(this.repeat("?", COMMA, values.Count)); 119 | inClause.Append(")"); 120 | 121 | return new TestExpression(inClause.ToString(), values); 122 | } 123 | 124 | public TestExpression In(string column, List values) 125 | { 126 | var inClause = new StringBuilder(string.Format(IN_TEMPLATE, this.getColumnName(column))); 127 | inClause.Append(" ("); 128 | inClause.Append(this.repeat("?", COMMA, values.Count)); 129 | inClause.Append(")"); 130 | 131 | return new TestExpression(inClause.ToString(), values); 132 | } 133 | 134 | private TestExpression comparisionPredicate(string columnCode, string op, object value) 135 | { 136 | var p = new List 137 | { 138 | value 139 | }; 140 | return new TestExpression(string.Format(COMPARISION_TEMPLATE, this.getColumnName(columnCode), op), p); 141 | } 142 | 143 | private string getColumnName(string columnCode) 144 | { 145 | return columnCode; 146 | } 147 | 148 | private string repeat(string s, string separator, int count) 149 | { 150 | var str = new StringBuilder((s.Length + separator.Length) * count); 151 | while (--count > 0) 152 | str.Append(s).Append(separator); 153 | 154 | return str.Append(s).ToString(); 155 | } 156 | 157 | public TestExpression Build(string query) 158 | { 159 | return RestSQL.Parse(query, this); 160 | } 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /RestSQL.Tests/RestSQL.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | false 7 | 8 | 7.3 9 | 10 | 1.0.8 11 | 12 | wareboss.com 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /RestSQL.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30413.136 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestSQL", "RestSQL\RestSQL.csproj", "{96CE99D3-5C62-42B9-99F6-B44B6ECF8C5D}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestSQL.Tests", "RestSQL.Tests\RestSQL.Tests.csproj", "{8CA2AFF0-A3F5-47F8-9D8C-8F9FC42D14A4}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestSQL.SqlKata", "RestSQL.SqlKata\RestSQL.SqlKata.csproj", "{3618BD0B-B683-43B2-A2C6-0C7760CD9E0C}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestSQL.SqlKata.Tests", "RestSQL.SqlKata.Tests\RestSQL.SqlKata.Tests.csproj", "{BFD8A85D-D4A0-4D64-B8FC-FA50E6BD4973}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestSQL.NPoco", "RestSQL.NPoco\RestSQL.NPoco.csproj", "{54910F9F-C226-491B-8780-4C7806D4AD8F}" 15 | EndProject 16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestSQL.NPoco.Tests", "RestSQL.NPoco.Tests\RestSQL.NPoco.Tests.csproj", "{0CB2E12E-D3E3-49D7-9AC8-D436A24F6E19}" 17 | EndProject 18 | Global 19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 20 | Debug|Any CPU = Debug|Any CPU 21 | Release|Any CPU = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 24 | {96CE99D3-5C62-42B9-99F6-B44B6ECF8C5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {96CE99D3-5C62-42B9-99F6-B44B6ECF8C5D}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {96CE99D3-5C62-42B9-99F6-B44B6ECF8C5D}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {96CE99D3-5C62-42B9-99F6-B44B6ECF8C5D}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {8CA2AFF0-A3F5-47F8-9D8C-8F9FC42D14A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {8CA2AFF0-A3F5-47F8-9D8C-8F9FC42D14A4}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {8CA2AFF0-A3F5-47F8-9D8C-8F9FC42D14A4}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {8CA2AFF0-A3F5-47F8-9D8C-8F9FC42D14A4}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {3618BD0B-B683-43B2-A2C6-0C7760CD9E0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {3618BD0B-B683-43B2-A2C6-0C7760CD9E0C}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {3618BD0B-B683-43B2-A2C6-0C7760CD9E0C}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {3618BD0B-B683-43B2-A2C6-0C7760CD9E0C}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {BFD8A85D-D4A0-4D64-B8FC-FA50E6BD4973}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {BFD8A85D-D4A0-4D64-B8FC-FA50E6BD4973}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {BFD8A85D-D4A0-4D64-B8FC-FA50E6BD4973}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {BFD8A85D-D4A0-4D64-B8FC-FA50E6BD4973}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {54910F9F-C226-491B-8780-4C7806D4AD8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 41 | {54910F9F-C226-491B-8780-4C7806D4AD8F}.Debug|Any CPU.Build.0 = Debug|Any CPU 42 | {54910F9F-C226-491B-8780-4C7806D4AD8F}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {54910F9F-C226-491B-8780-4C7806D4AD8F}.Release|Any CPU.Build.0 = Release|Any CPU 44 | {0CB2E12E-D3E3-49D7-9AC8-D436A24F6E19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 45 | {0CB2E12E-D3E3-49D7-9AC8-D436A24F6E19}.Debug|Any CPU.Build.0 = Debug|Any CPU 46 | {0CB2E12E-D3E3-49D7-9AC8-D436A24F6E19}.Release|Any CPU.ActiveCfg = Release|Any CPU 47 | {0CB2E12E-D3E3-49D7-9AC8-D436A24F6E19}.Release|Any CPU.Build.0 = Release|Any CPU 48 | EndGlobalSection 49 | GlobalSection(SolutionProperties) = preSolution 50 | HideSolutionNode = FALSE 51 | EndGlobalSection 52 | GlobalSection(ExtensibilityGlobals) = postSolution 53 | SolutionGuid = {F5EE5E4C-9D87-47C3-93F5-7008FACAD8D7} 54 | EndGlobalSection 55 | EndGlobal 56 | -------------------------------------------------------------------------------- /RestSQL/IExpressionBuilder.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | //Ported from https://github.com/mmrath/rsql-parser 16 | */ 17 | using System.Collections.Generic; 18 | 19 | namespace RestSQL 20 | { 21 | public interface IExpressionBuilder 22 | { 23 | T Or(T expression1, T expression2); 24 | 25 | T And(T expression1, T expression2); 26 | 27 | T Parenthesize(T expression); 28 | 29 | T Equal(string column, object value); 30 | 31 | T NotEqual(string column, object value); 32 | 33 | T LessOrEqual(string column, object value); 34 | 35 | T LessThan(string column, object value); 36 | 37 | T GreaterOrEqual(string column, object value); 38 | 39 | T GreaterThan(string column, object value); 40 | 41 | T IsNotNull(string column); 42 | 43 | T IsNull(string column); 44 | 45 | T NotLike(string column, object value); 46 | 47 | T Like(string column, object value); 48 | 49 | T NotBetween(string column, object start, object end); 50 | 51 | T Between(string column, object start, object end); 52 | 53 | T NotIn(string column, List values); 54 | 55 | T In(string column, List values); 56 | 57 | T Build(string query); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /RestSQL/RestSQL.cs: -------------------------------------------------------------------------------- 1 | using Antlr4.Runtime; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace RestSQL 7 | { 8 | public static class RestSQL 9 | { 10 | public static T Parse(string query, IExpressionBuilder expressionBuilder) 11 | { 12 | var lexer = new RsqlLexer(new AntlrInputStream(query)); 13 | var tokenStream = new CommonTokenStream(lexer); 14 | var rsqlParser = new RsqlParser(tokenStream); 15 | var tree = rsqlParser.expression(); 16 | var rsqlStatement = new RsqlExpressionVisitor(expressionBuilder).Visit(tree); 17 | 18 | return rsqlStatement; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /RestSQL/RestSQL.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.1 5 | 8.0 6 | true 7 | Igor Quirino 8 | wareboss.com 9 | https://github.com/iquirino/RestSQL 10 | C# Sql Where Clause Parser to be used as Rest Parameters to filter data 11 | https://github.com/iquirino/RestSQL 12 | SQL, SQL PARSER, QUERY BUILDER, SQLKATA, RESTSQL, REST 13 | Copyright 2020 Igor Quirino (wareboss.com) 14 | https://raw.githubusercontent.com/iquirino/RestSQL/master/LICENSE 15 | 1.0.10.0 16 | 1.0.10.0 17 | 1.0.10 18 | README.md 19 | 20 | 21 | 22 | 23 | all 24 | runtime; build; native; contentfiles; analyzers 25 | 26 | 27 | all 28 | runtime; build; native; contentfiles; analyzers 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /RestSQL/RsqlExpressionVisitor.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | //Ported from https://github.com/mmrath/rsql-parser 16 | */ 17 | using System; 18 | using System.Collections.Generic; 19 | using System.Globalization; 20 | using System.Linq; 21 | 22 | namespace RestSQL 23 | { 24 | public class RsqlExpressionVisitor 25 | { 26 | private readonly IExpressionBuilder expressionBuilder; 27 | public RsqlExpressionVisitor(IExpressionBuilder expressionBuilder) 28 | { 29 | this.expressionBuilder = expressionBuilder; 30 | } 31 | 32 | public T Visit(RsqlParser.ExpressionContext context) 33 | { 34 | if (context.booleanValueExpression() != null) 35 | return this.VisitBooleanValueExpression(context.booleanValueExpression()); 36 | return default; 37 | } 38 | 39 | private T VisitBooleanValueExpression(RsqlParser.BooleanValueExpressionContext booleanValueExpressionContext) 40 | { 41 | 42 | if (booleanValueExpressionContext.orPredicate() != null) 43 | return this.VisitOrPredicate(booleanValueExpressionContext.orPredicate()); 44 | else 45 | throw new ArgumentNullException("Or predicate expected"); 46 | } 47 | 48 | private T VisitOrPredicate(RsqlParser.OrPredicateContext orPredicateContext) 49 | { 50 | T andStmt = default; 51 | if (orPredicateContext.andPredicate() != null) 52 | andStmt = this.VisitAndStmt(orPredicateContext.andPredicate()); 53 | 54 | T orStmt = default; 55 | if (orPredicateContext.orPredicate() != null && orPredicateContext.orPredicate().Any()) 56 | { 57 | foreach (var orExp in orPredicateContext.orPredicate()) 58 | orStmt = this.expressionBuilder.Or(orStmt, this.VisitOrPredicate(orExp)); 59 | } 60 | return this.expressionBuilder.Or(andStmt, orStmt); 61 | } 62 | 63 | private T VisitAndStmt(RsqlParser.AndPredicateContext andPredicateContext) 64 | { 65 | T primaryBooleanStmt = default; 66 | 67 | if (andPredicateContext.booleanPrimary() != null) 68 | primaryBooleanStmt = this.VisitPrimaryBooleanStmt(andPredicateContext.booleanPrimary()); 69 | 70 | T andStmt = default; 71 | if (andPredicateContext.andPredicate() != null && andPredicateContext.andPredicate().Any()) 72 | { 73 | foreach (var and in andPredicateContext.andPredicate()) 74 | andStmt = this.expressionBuilder.And(andStmt, this.VisitAndStmt(and)); 75 | } 76 | return this.expressionBuilder.And(primaryBooleanStmt, andStmt); 77 | 78 | } 79 | 80 | private T VisitPrimaryBooleanStmt(RsqlParser.BooleanPrimaryContext booleanPrimaryContext) 81 | { 82 | if (booleanPrimaryContext.predicate() != null) 83 | return this.VisitPredicate(booleanPrimaryContext.predicate()); 84 | else if (booleanPrimaryContext.booleanPredicand() != null) 85 | return this.VisitBooleanPredicand(booleanPrimaryContext.booleanPredicand()); 86 | else 87 | return default; 88 | } 89 | 90 | private T VisitBooleanPredicand(RsqlParser.BooleanPredicandContext booleanPredicandContext) 91 | { 92 | if (booleanPredicandContext.parenthesizedBooleanValueExpression() != null && 93 | booleanPredicandContext.parenthesizedBooleanValueExpression().booleanValueExpression() != null) 94 | return this.expressionBuilder.Parenthesize(this.VisitBooleanValueExpression( 95 | booleanPredicandContext.parenthesizedBooleanValueExpression().booleanValueExpression())); 96 | 97 | return default; 98 | } 99 | 100 | private T VisitPredicate(RsqlParser.PredicateContext predicate) 101 | { 102 | if (predicate.comparisonPredicate() != null) 103 | return this.VisitComparisionPredicate(predicate.comparisonPredicate()); 104 | else if (predicate.betweenPredicate() != null) 105 | return this.VisitBetweenPredicate(predicate.betweenPredicate()); 106 | else if (predicate.inPredicate() != null) 107 | return this.VisitInPredicate(predicate.inPredicate()); 108 | else if (predicate.patternMatchingPredicate() != null) 109 | return this.VisitPatternMatchingPredicate(predicate.patternMatchingPredicate()); 110 | else if (predicate.nullPredicate() != null) 111 | return this.VisitNullPredicate(predicate.nullPredicate()); 112 | else 113 | throw new InvalidOperationException("Unknown predicate type in:" + predicate.GetText()); 114 | } 115 | 116 | private T VisitNullPredicate(RsqlParser.NullPredicateContext nullPredicateContext) 117 | { 118 | string column = nullPredicateContext.columnName().Identifier().GetText(); 119 | if (nullPredicateContext.NOT() != null) 120 | return this.expressionBuilder.IsNotNull(column); 121 | else 122 | return this.expressionBuilder.IsNull(column); 123 | } 124 | 125 | private T VisitPatternMatchingPredicate(RsqlParser.PatternMatchingPredicateContext patternMatchingPredicateContext) 126 | { 127 | string column = patternMatchingPredicateContext.columnName().Identifier().GetText(); 128 | object value = valueFromStringLiteral(patternMatchingPredicateContext.Character_String_Literal().GetText()); 129 | if (patternMatchingPredicateContext.patternMatcher().NOT() != null) 130 | return this.expressionBuilder.NotLike(column, value); 131 | else 132 | return this.expressionBuilder.Like(column, value); 133 | } 134 | 135 | private T VisitInPredicate(RsqlParser.InPredicateContext inPredicateContext) 136 | { 137 | string column = inPredicateContext.columnName().Identifier().GetText(); 138 | var values = GetValues(inPredicateContext.inPredicateValue().inValueList().valueExpression()); 139 | if (inPredicateContext.NOT() != null) 140 | return this.expressionBuilder.NotIn(column, values); 141 | else 142 | return this.expressionBuilder.In(column, values); 143 | } 144 | 145 | private T VisitBetweenPredicate(RsqlParser.BetweenPredicateContext betweenPredicateContext) 146 | { 147 | string column = betweenPredicateContext.columnName().Identifier().GetText(); 148 | object start = this.GetValue(betweenPredicateContext.betweenBegin().valueExpression()); 149 | object end = this.GetValue(betweenPredicateContext.betweenEnd().valueExpression()); 150 | 151 | if (betweenPredicateContext.NOT() != null) 152 | return this.expressionBuilder.NotBetween(column, start, end); 153 | else 154 | return this.expressionBuilder.Between(column, start, end); 155 | } 156 | 157 | private T VisitComparisionPredicate(RsqlParser.ComparisonPredicateContext comparisonPredicateContext) 158 | { 159 | if (comparisonPredicateContext.comparisionOperator().EQUAL() != null) 160 | { 161 | return this.expressionBuilder.Equal(comparisonPredicateContext.left.Identifier().GetText(), 162 | this.GetValue(comparisonPredicateContext.valueExpression())); 163 | } 164 | else if (comparisonPredicateContext.comparisionOperator().NOT_EQUAL() != null) 165 | { 166 | return this.expressionBuilder.NotEqual(comparisonPredicateContext.left.Identifier().GetText(), 167 | this.GetValue(comparisonPredicateContext.valueExpression())); 168 | } 169 | else if (comparisonPredicateContext.comparisionOperator().LEQ() != null) 170 | { 171 | return this.expressionBuilder.LessOrEqual(comparisonPredicateContext.left.Identifier().GetText(), 172 | this.GetValue(comparisonPredicateContext.valueExpression())); 173 | } 174 | else if (comparisonPredicateContext.comparisionOperator().LTH() != null) 175 | { 176 | return this.expressionBuilder.LessThan(comparisonPredicateContext.left.Identifier().GetText(), 177 | this.GetValue(comparisonPredicateContext.valueExpression())); 178 | } 179 | else if (comparisonPredicateContext.comparisionOperator().GEQ() != null) 180 | { 181 | return this.expressionBuilder.GreaterOrEqual(comparisonPredicateContext.left.Identifier().GetText(), 182 | this.GetValue(comparisonPredicateContext.valueExpression())); 183 | } 184 | else if (comparisonPredicateContext.comparisionOperator().GTH() != null) 185 | { 186 | return this.expressionBuilder.GreaterThan(comparisonPredicateContext.left.Identifier().GetText(), 187 | this.GetValue(comparisonPredicateContext.valueExpression())); 188 | } 189 | else 190 | { 191 | throw new InvalidOperationException("Comparision predicate not recognized:" + comparisonPredicateContext.GetText()); 192 | } 193 | } 194 | 195 | private List GetValues(RsqlParser.ValueExpressionContext[] valueExpressionContexts) 196 | { 197 | return GetValues(valueExpressionContexts.ToList()); 198 | } 199 | 200 | private List GetValues(List valueExpressionContexts) 201 | { 202 | var p = new List(); 203 | 204 | foreach (RsqlParser.ValueExpressionContext context in valueExpressionContexts) 205 | p.Add(this.GetValue(context)); 206 | 207 | return p; 208 | } 209 | private object GetValue(RsqlParser.ValueExpressionContext valueExpressionContext) 210 | { 211 | object value; 212 | 213 | if (valueExpressionContext.Character_String_Literal() != null) 214 | { 215 | string literal = valueExpressionContext.Character_String_Literal().GetText(); 216 | return this.valueFromStringLiteral(literal); 217 | } 218 | else if (valueExpressionContext.numericValueExpression() != null) 219 | { 220 | var numericValueExpressionContext = valueExpressionContext.numericValueExpression(); 221 | if (numericValueExpressionContext.numericPrimary().NUMBER() != null) 222 | value = long.Parse(numericValueExpressionContext.GetText()); 223 | else 224 | value = decimal.Parse(numericValueExpressionContext.GetText()); 225 | } 226 | else if (valueExpressionContext.Identifier() != null) 227 | { 228 | value = valueExpressionContext.Identifier().GetText(); 229 | } 230 | else if (valueExpressionContext.dateTimeExpression() is { } dt) 231 | { 232 | if (dt.DateLiteral() is { } date) 233 | { 234 | value = DateTime.ParseExact(date.GetText(), "yyyy-MM-dd", CultureInfo.InvariantCulture); 235 | } else if (dt.DateTimeLiteral() is { } dateTime) 236 | { 237 | var text = dateTime.GetText().Replace('T', ' '); 238 | value = DateTime.ParseExact(text, "yyyy-MM-dd HH-mm-ss", CultureInfo.InvariantCulture); 239 | } 240 | else 241 | { 242 | throw new InvalidOperationException(); 243 | } 244 | } 245 | else 246 | { 247 | throw new InvalidOperationException("Value is illegal:" + valueExpressionContext.GetText()); 248 | } 249 | return value; 250 | } 251 | 252 | private string valueFromStringLiteral(string literal) 253 | { 254 | literal = literal.Substring(1); // remove first quote 255 | literal = literal.Substring(0, literal.Length - 1); // remove last quote 256 | return literal; 257 | } 258 | } 259 | } 260 | -------------------------------------------------------------------------------- /RestSQL/RsqlLexer.g4: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | //Copied from https://github.com/camertron/SQLParser 16 | //Copied from https://github.com/mmrath/rsql-parser 17 | */ 18 | lexer grammar RsqlLexer; 19 | 20 | @header { 21 | } 22 | 23 | @members { 24 | } 25 | 26 | 27 | /* 28 | =============================================================================== 29 | Tokens for Case Insensitive Keywords 30 | =============================================================================== 31 | */ 32 | fragment A 33 | : 'A' | 'a'; 34 | 35 | fragment B 36 | : 'B' | 'b'; 37 | 38 | fragment C 39 | : 'C' | 'c'; 40 | 41 | fragment D 42 | : 'D' | 'd'; 43 | 44 | fragment E 45 | : 'E' | 'e'; 46 | 47 | fragment F 48 | : 'F' | 'f'; 49 | 50 | fragment G 51 | : 'G' | 'g'; 52 | 53 | fragment H 54 | : 'H' | 'h'; 55 | 56 | fragment I 57 | : 'I' | 'i'; 58 | 59 | fragment J 60 | : 'J' | 'j'; 61 | 62 | fragment K 63 | : 'K' | 'k'; 64 | 65 | fragment L 66 | : 'L' | 'l'; 67 | 68 | fragment M 69 | : 'M' | 'm'; 70 | 71 | fragment N 72 | : 'N' | 'n'; 73 | 74 | fragment O 75 | : 'O' | 'o'; 76 | 77 | fragment P 78 | : 'P' | 'p'; 79 | 80 | fragment Q 81 | : 'Q' | 'q'; 82 | 83 | fragment R 84 | : 'R' | 'r'; 85 | 86 | fragment S 87 | : 'S' | 's'; 88 | 89 | fragment T 90 | : 'T' | 't'; 91 | 92 | fragment U 93 | : 'U' | 'u'; 94 | 95 | fragment V 96 | : 'V' | 'v'; 97 | 98 | fragment W 99 | : 'W' | 'w'; 100 | 101 | fragment X 102 | : 'X' | 'x'; 103 | 104 | fragment Y 105 | : 'Y' | 'y'; 106 | 107 | fragment Z 108 | : 'Z' | 'z'; 109 | 110 | /* 111 | =============================================================================== 112 | Reserved Keywords 113 | =============================================================================== 114 | */ 115 | 116 | AND : A N D; 117 | IN : I N; 118 | IS : I S; 119 | LIKE : L I K E; 120 | NOT : N O T; 121 | NULL : N U L L; 122 | OR : O R; 123 | BETWEEN : B E T W E E N; 124 | 125 | 126 | // Operators 127 | Similar_To : '~'; 128 | Not_Similar_To : '!~'; 129 | Similar_To_Case_Insensitive : '~*'; 130 | Not_Similar_To_Case_Insensitive : '!~*'; 131 | 132 | EQUAL : '='; 133 | COLON : ':'; 134 | SEMI_COLON : ';'; 135 | COMMA : ','; 136 | NOT_EQUAL : '<>' | '!=' | '~='| '^=' ; 137 | LTH : '<' ; 138 | LEQ : '<='; 139 | GTH : '>'; 140 | GEQ : '>='; 141 | LEFT_PAREN : '('; 142 | RIGHT_PAREN : ')'; 143 | PLUS : '+'; 144 | MINUS : '-'; 145 | MULTIPLY: '*'; 146 | DIVIDE : '/'; 147 | MODULAR : '%'; 148 | DOT : '.'; 149 | UNDERLINE : '_'; 150 | VERTICAL_BAR : '|'; 151 | QUOTE : '\''; 152 | DOUBLE_QUOTE : '"'; 153 | 154 | NUMBER : Digit+; 155 | 156 | fragment 157 | Digit : '0'..'9'; 158 | 159 | REAL_NUMBER 160 | : ('0'..'9')+ '.' ('0'..'9')* EXPONENT? 161 | | '.' ('0'..'9')+ EXPONENT? 162 | | ('0'..'9')+ EXPONENT 163 | ; 164 | 165 | BlockComment 166 | : '/*' .*? '*/' -> skip 167 | ; 168 | 169 | LineComment 170 | : '--' ~[\r\n]* -> skip 171 | ; 172 | 173 | /* 174 | =============================================================================== 175 | Identifiers 176 | =============================================================================== 177 | */ 178 | 179 | Identifier 180 | : Regular_Identifier 181 | ; 182 | 183 | fragment 184 | Regular_Identifier 185 | : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|Digit|'_')* 186 | ; 187 | 188 | /* 189 | =============================================================================== 190 | Literal 191 | =============================================================================== 192 | */ 193 | 194 | // Some Unicode Character Ranges 195 | fragment 196 | Control_Characters : '\u0001' .. '\u001F'; 197 | fragment 198 | Extended_Control_Characters : '\u0080' .. '\u009F'; 199 | 200 | Character_String_Literal 201 | : QUOTE ( ESC_SEQ | ~('\\'|'\'') )* QUOTE 202 | ; 203 | 204 | DateLiteral 205 | : Digit Digit Digit Digit '-' Digit Digit '-' Digit Digit 206 | ; 207 | 208 | TimeLiteral 209 | : Digit Digit '-' Digit Digit '-' Digit Digit 210 | ; 211 | 212 | DateTimeLiteral 213 | : DateLiteral 'T' TimeLiteral 214 | ; 215 | 216 | fragment 217 | EXPONENT : ('e'|'E') ('+'|'-')? ('0'..'9')+ ; 218 | 219 | fragment 220 | HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ; 221 | 222 | fragment 223 | ESC_SEQ 224 | : '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\') 225 | | UNICODE_ESC 226 | | OCTAL_ESC 227 | ; 228 | 229 | fragment 230 | OCTAL_ESC 231 | : '\\' ('0'..'3') ('0'..'7') ('0'..'7') 232 | | '\\' ('0'..'7') ('0'..'7') 233 | | '\\' ('0'..'7') 234 | ; 235 | 236 | fragment 237 | UNICODE_ESC 238 | : '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT 239 | ; 240 | 241 | /* 242 | =============================================================================== 243 | Whitespace Tokens 244 | =============================================================================== 245 | */ 246 | 247 | Space 248 | : ' ' -> skip 249 | ; 250 | 251 | White_Space 252 | : ( Control_Characters | Extended_Control_Characters )+ -> skip 253 | ; 254 | 255 | 256 | BAD 257 | : . -> skip 258 | ; -------------------------------------------------------------------------------- /RestSQL/RsqlLexer.g4.cs: -------------------------------------------------------------------------------- 1 | namespace RestSQL 2 | { 3 | partial class RsqlLexer 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /RestSQL/RsqlParser.g4: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | //Copied from https://github.com/camertron/SQLParser 16 | //Copied from https://github.com/mmrath/rsql-parser 17 | */ 18 | parser grammar RsqlParser; 19 | 20 | options 21 | { 22 | language=csharp; 23 | tokenVocab = RsqlLexer; 24 | } 25 | 26 | 27 | expression:booleanValueExpression; 28 | 29 | booleanValueExpression 30 | : orPredicate 31 | ; 32 | 33 | orPredicate 34 | : andPredicate (OR orPredicate)* 35 | ; 36 | 37 | andPredicate 38 | : booleanPrimary (AND andPredicate)* 39 | ; 40 | 41 | booleanPrimary 42 | : predicate 43 | | booleanPredicand 44 | ; 45 | 46 | booleanPredicand 47 | : parenthesizedBooleanValueExpression 48 | ; 49 | 50 | parenthesizedBooleanValueExpression 51 | : LEFT_PAREN booleanValueExpression RIGHT_PAREN 52 | ; 53 | 54 | predicate 55 | : comparisonPredicate 56 | | betweenPredicate 57 | | inPredicate 58 | | patternMatchingPredicate // like predicate and other similar predicates 59 | | nullPredicate 60 | ; 61 | 62 | comparisonPredicate 63 | : left=columnName c=comparisionOperator right=valueExpression 64 | ; 65 | 66 | comparisionOperator 67 | : EQUAL 68 | | NOT_EQUAL 69 | | LTH 70 | | LEQ 71 | | GTH 72 | | GEQ 73 | ; 74 | 75 | betweenPredicate 76 | : predicand=columnName (NOT)? BETWEEN betweenBegin AND betweenEnd 77 | ; 78 | 79 | betweenBegin 80 | :valueExpression 81 | ; 82 | 83 | betweenEnd 84 | :valueExpression 85 | ; 86 | 87 | inPredicate 88 | : predicand=columnName NOT? IN inPredicateValue 89 | ; 90 | 91 | inPredicateValue 92 | : LEFT_PAREN inValueList RIGHT_PAREN 93 | ; 94 | 95 | inValueList 96 | : valueExpression (COMMA valueExpression)* 97 | ; 98 | 99 | patternMatchingPredicate 100 | : f=columnName patternMatcher s=Character_String_Literal 101 | ; 102 | 103 | patternMatcher 104 | : NOT? LIKE 105 | ; 106 | 107 | nullPredicate 108 | : predicand=columnName IS (n=NOT)? NULL 109 | ; 110 | 111 | valueExpression 112 | : Character_String_Literal 113 | | numericValueExpression 114 | | Identifier 115 | | dateTimeExpression 116 | ; 117 | 118 | dateTimeExpression 119 | : DateTimeLiteral 120 | | DateLiteral 121 | ; 122 | 123 | numericValueExpression 124 | : (sign)? numericPrimary 125 | ; 126 | 127 | numericPrimary 128 | : NUMBER 129 | | REAL_NUMBER 130 | ; 131 | 132 | sign 133 | : PLUS | MINUS 134 | ; 135 | 136 | columnName 137 | : Identifier 138 | ; -------------------------------------------------------------------------------- /RestSQL/RsqlParser.g4.cs: -------------------------------------------------------------------------------- 1 | namespace RestSQL 2 | { 3 | partial class RsqlParser 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /RestSQL/RsqlQueryType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace RestSQL 6 | { 7 | public enum RSqlQueryType 8 | { 9 | Between, 10 | Equal, 11 | GreaterOrEqual, 12 | In, 13 | GreatherThan, 14 | IsNotNull, 15 | IsNull, 16 | LessOrEqual, 17 | Like, 18 | LessThan, 19 | NotBetween, 20 | NotEqual, 21 | NotIn, 22 | NotLike 23 | } 24 | } 25 | --------------------------------------------------------------------------------