diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index de48a5a..ea629cd 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -4,6 +4,7 @@ categories: - title: '🔥 Breaking Changes' labels: - 'breaking' + - 'break' - title: '🚀 Features' labels: - 'feature' @@ -37,6 +38,10 @@ template: | **Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION autolabeler: + - label: 'feature' + title: + - '/feature/i' + - '/feat/i' - label: 'documentation' files: - '*.md' @@ -56,6 +61,3 @@ autolabeler: - label: 'deprecation' title: - '/deprecate/i' - - label: 'feature' - title: - - '/feature/i' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b26b9fc --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Scala CI +on: + pull_request: + push: + branches: [ "master" ] +jobs: + build: + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + java: 8 + - os: ubuntu-latest + java: 11 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: ${{ matrix.java }} + + - uses: sbt/setup-sbt@v1 + + - name: Create header and run scalafmt + run: sbt headerCreateAll scalafmtAll + + - name: Build and Test + run: sbt -v +test + + # Optional: This step uploads information to the GitHub dependency graph and unblocking Dependabot alerts for the repository + #- name: Upload dependency graph + # uses: scalacenter/sbt-dependency-submission@ab086b50c947c9774b70f39fc7f6e20ca2706c91 diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index dbbae59..6dc9eaa 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -1,29 +1,24 @@ name: Release on: push: - tags: - - v* + branches: [master, main] + tags: ["*"] jobs: publish: runs-on: ubuntu-latest steps: - - - name: Checkout - uses: actions/checkout@v4 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - - name: Set up JDK - uses: actions/setup-java@v4 + - uses: actions/setup-java@v4 with: distribution: temurin - java-version: 8 + java-version: 11 cache: sbt - - - name: Release - run: sbt ci-release + - uses: sbt/setup-sbt@v1 + - run: sbt ci-release env: PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} PGP_SECRET: ${{ secrets.PGP_SECRET }} - SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} diff --git a/.github/workflows/scala-ci.yml b/.github/workflows/scala-ci.yml deleted file mode 100644 index 517f88a..0000000 --- a/.github/workflows/scala-ci.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Scala CI -on: - pull_request: - branches: [ "master" ] - -jobs: - checks: - runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up JDK - uses: actions/setup-java@v4 - with: - distribution: temurin - java-version: 8 - cache: sbt - - - name: Check scalafmt - run: sbt scalafmtCheckAll - - - name: Check build - run: sbt clean compile test doc \ No newline at end of file diff --git a/.scalafmt.conf b/.scalafmt.conf index 78e9bb6..a78cf64 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -21,4 +21,7 @@ docstrings.style = Asterisk rewrite { rules = [SortImports, RedundantBraces] redundantBraces.maxLines = 1 -} \ No newline at end of file +} + +docstrings.wrap = no +importSelectors = singleLine diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..e806fa2 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,14 @@ +# Code of Conduct + +Every member of our community has the right to have their identity respected. The Typelevel community is dedicated to providing a positive experience for everyone, regardless of age, gender identity and expression, sexual orientation, disability, neurodivergence, physical appearance, body size, ethnicity, nationality, race, or religion (or lack thereof), education, or socio-economic status. + +Everyone is expected to follow the [Typelevel Code of Conduct] when discussing the project on the available communication channels. + +## Moderation + +If you have any questions, concerns, or moderation requests, please contact a member of the [Typelevel Code of Conduct Committee] or reach out to a project moderator: + +- [Rafael Fernandez](mailto:hi@rafaelfernandez.dev) + +[Typelevel Code of Conduct]: https://typelevel.org/code-of-conduct +[Typelevel Code of Conduct Committee]: https://typelevel.org/code-of-conduct#contact diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..f7e6399 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,66 @@ +# Contributing to Criteria4s + +Thank you for considering contributing to Criteria4s! We welcome contributions from the community to improve this project. Below are some guidelines to help you get started. + +## Code of Conduct + +Please adhere to our [Code of Conduct](CODE_OF_CONDUCT.md) during your interactions in the project repository. We strive to provide a welcoming and inclusive environment for all contributors. + +## How to Contribute + +### 1. Fork the Repository + +Fork the repository on GitHub by clicking the "Fork" button at the top right of the page. + +### 2. Clone Your Fork + +Clone your fork to your local machine: + +```sh +git clone https://github.com/your-username/criteria4s.git +cd criteria4s +``` + +### 3. Create a Branch + +Create a branch for your feature or bug fix: + +```sh +git checkout -b my-feature-branch +``` + +### 4. Make Changes + +Make your changes to the code. Ensure your code adheres to the project's coding standards. + +### 5. Commit Your Changes + +Commit your changes with a descriptive commit message: + +```sh +git commit -m "Add feature X" +``` + +### 6. Push to Your Fork + +Push your changes to your fork on GitHub: + +```sh +git push origin my-feature-branch +``` + +### 7. Open a Pull Request + +Go to the original repository and open a pull request. Provide a clear and descriptive title and description of your changes. + +## Code of Conduct + +Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. + +## Reporting Issues + +If you find a bug or have a feature request, please create an issue on GitHub. Provide as much detail as possible to help us address it. + +## Thank You! + +Thank you for contributing to Criteria4s! Your help is greatly appreciated. \ No newline at end of file diff --git a/LICENSE b/LICENSE index c319da3..772ba7c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,201 +1,21 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. +MIT License + +Copyright (c) 2024 Rafael Fernandez + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 93fdf69..6747239 100644 --- a/README.md +++ b/README.md @@ -1,87 +1,35 @@ -![Sonatype Nexus (Releases)](https://img.shields.io/nexus/r/io.github.rafafrdz/criteria4s-core_2.13?server=https%3A%2F%2Fs01.oss.sonatype.org&style=flat-square&label=Sonatype&labelColor=%20&color=%2acf45%20%20) [![License](https://img.shields.io/badge/license-Apache%202-blue.svg?style=flat-square&label=License)](https://github.com/rafafrdz/criteria4s?tab=Apache-2.0-1-ov-file#readme) +![Sonatype Nexus (Releases)](https://img.shields.io/nexus/r/com.eff3ct/criteria4s-core_2.13?server=https%3A%2F%2Fs01.oss.sonatype.org&style=flat-square&label=Sonatype&labelColor=%20&color=%2acf45%20%20) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) # Criteria4s -Criteria4s is a simple domain-specific language (DSL) to define criteria and predicate expressions for any data stores -by using Scala type class mechanisms in a type-safe way. It pretends to be agnostic to any data store, and it is -extensible to support any kind of data stores. - -## Formal Definition of the Expressions - -The formal definition of the Criteria4s' type-classes (expressions) is as follows: - -```text -Criteria := Conjuction Criteria Criteria | Predicate | Value -Predicate := UnaryPred Ref | BinaryPred Ref Ref -Ref := Value | Col -Conjuction := AND | OR -UnaryPred := IS_NULL | IS_NOT_NULL ... -BinaryPred := EQ | NEQ | GT | LT | GEQ | LEQ | IN | LIKE ... -``` - -Where: - -- `Criteria` is the main expression of the DSL -- `Conjuction` is the conjunction operator expression -- `UnaryPredOp` is the unary predicate operator expression -- `BinaryPredOp` is the binary predicate operator expression -- `Ref` is a reference to a value or a column -- `Value` is a value expression of a certain type `T` -- `Col` is a column expression +Criteria4s is a straightforward domain-specific language (DSL) designed to define criteria and predicate expressions for any data store using Scala's type class mechanisms in a type-safe manner. Its core is designed to be agnostic to any specific data store, making it extensible and capable of supporting a variety of data storage systems. ## Getting Started -To use dsl of Criteria4s, you need to add the following dependency to your project: +To utilize the Criteria4s DSL in your project, add the following dependencies to your build configuration: -**SonaType Repository** +### Sonatype Repository -- Core library: [criteria4s-core](https://central.sonatype.com/artifact/io.github.rafafrdz/criteria4s-core_2.13) -- SQL implementation: [criteria4s-sql](https://central.sonatype.com/artifact/io.github.rafafrdz/criteria4s-sql_2.13) -- MongoDB dialect - implementation: [criteria4s-mongodb](https://central.sonatype.com/artifact/io.github.rafafrdz/criteria4s-mongodb_2.13) +- **Core library**: [criteria4s-core](https://central.sonatype.com/artifact/com.eff3ct/criteria4s-core_2.13) +- **SQL implementation**: [criteria4s-sql](https://central.sonatype.com/artifact/com.eff3ct/criteria4s-sql_2.13) +- **MongoDB implementation**: [criteria4s-mongodb](https://central.sonatype.com/artifact/com.eff3ct/criteria4s-mongodb_2.13) -**SBT** +### SBT -```scala -libraryDependencies += "io.github.rafafrdz" %% "criteria4s-core" % "" // Core library -libraryDependencies += "io.github.rafafrdz" %% "criteria4s-sql" % "" // SQL implementation -libraryDependencies += "io.github.rafafrdz" %% "criteria4s-mongodb" % "" // MongoDB implementation - -``` +Add these to your `build.sbt`: -**Maven** - -```xml - - - - io.github.rafafrdz - criteria4s-core_2.13 - 0.8.2 - - - - - io.github.rafafrdz - criteria4s-core_2.13 - 0.8.2 - - - - - io.github.rafafrdz - criteria4s-mongodb_2.13 - 0.8.2 - - +```scala +libraryDependencies += "com.eff3ct" %% "criteria4s-core" % "" // Core library +libraryDependencies += "com.eff3ct" %% "criteria4s-sql" % "" // SQL implementation +libraryDependencies += "com.eff3ct" %% "criteria4s-mongodb" % "" // MongoDB implementation ``` > [!IMPORTANT] -> Criteria4s is a work in progress and it is not ready for production use. Also, it is just available for Scala 2.13. +> Criteria4s is currently a work in progress and not ready for production use. It is available exclusively for Scala 2.13. -## Dialects +## Dialects Supported -Criteria4s is extensible to support any kind of data stores. Currently, it supports the following **dialects**: +Criteria4s is extensible, supporting various types of data stores. Presently, it supports the following dialects: | Dialect | Package | |-------------|:-------------------------------------------------------------------------------------------| @@ -91,32 +39,31 @@ Criteria4s is extensible to support any kind of data stores. Currently, it suppo ## Examples -Here, we will show some examples of how to use the Criteria DSL. You can find more examples in -the [`criteria4s-examples`](./examples/src/main/scala/io/github/rafafrdz/criteria4s/examples) module. +Here are examples demonstrating how to use the Criteria DSL. More samples are available in the [`criteria4s-examples`](./examples/src/main/scala/io/github/rafafrdz/criteria4s/examples) module. ### Imports -First, we need to import the Criteria4s DSL and the SQL dialect: +Start by importing the Criteria4s DSL and the SQL dialect: ```scala -import io.github.rafafrdz.criteria4s.core._ -import io.github.rafafrdz.criteria4s.examples.datastores._ -import io.github.rafafrdz.criteria4s.extensions._ -import io.github.rafafrdz.criteria4s.functions._ +import com.eff3ct.criteria4s.core._ +import com.eff3ct.criteria4s.examples.datastores._ +import com.eff3ct.criteria4s.extensions._ +import com.eff3ct.criteria4s.functions._ ``` ### Defining Criteria Expressions -We can define criteria expressions in a polymorphic way by using the Criteria DSL. You can find more definitions -examples -in the [`Defining Criteria Expressions`](./doc/defining-criteria-expressions.md) document. +Define criteria expressions in a polymorphic way using the Criteria DSL. Additional examples are provided in the [`Defining Criteria Expressions`](./doc/defining-criteria-expressions.md) document. ```scala def expr[T <: CriteriaTag : LEQ : EQ : AND : OR : Show[Column, *]]: Criteria[T] = (col[T]("field1") leq lit(3)) and (col[T]("field2") leq lit(4)) or (col[T]("field3") === lit("c")) ``` -#### Case of use +#### Use Cases + +The following code snippets demonstrate how to use the defined criteria expressions: ```scala def ageCriteria[T <: CriteriaTag : GT : LT : AND : Show[Column, *]]: Criteria[T] = @@ -128,18 +75,16 @@ def refCriteria[T <: CriteriaTag : EQ : Show[Column, *]](fieldName: String, id: ### Evaluating Criteria Expressions -And then we can use those expressions defined belows in order to generate criteria expressions for different -datastores by importing the corresponding dialects. You can find evaluation examples for some different dialects in the -following documents: +Utilize these expressions to generate criteria for different data stores by importing the corresponding dialects. Evaluation examples for various dialects are available in the following documents: -- [PostgreSQL Dialect](./doc/postgresql-dialect-evaluating.md) -- [MongoDB Dialect](./doc/mongodb-dialect-evaluating.md) -- [MySQL Dialect](./doc/mysql-dialect-evaluating.md) -- [Custom Dialect](./doc/custom-dialect-evaluating.md) +- [PostgreSQL Dialect](./doc/postgresql-dialect-evaluating.md): Evaluate criteria expressions for PostgreSQL data stores. +- [MongoDB Dialect](./doc/mongodb-dialect-evaluating.md): Evaluate criteria expressions for MongoDB data stores. +- [MySQL Dialect](./doc/mysql-dialect-evaluating.md): Evaluate criteria expressions for MySQL data stores. +- [Custom Dialect](./doc/custom-dialect-evaluating.md): Evaluate criteria expressions for custom data stores. ### Inline Criteria DSL -Or maybe we can use the Criteria DSL inline: +Leverage the Criteria DSL in an inline manner: ```scala (col[PostgreSQL]("field1") leq lit(3)) and (col[PostgreSQL]("field2") leq lit(4)) or (col[PostgreSQL]("field3") === lit("c")) diff --git a/build.sbt b/build.sbt index c00d67a..30cbb0e 100644 --- a/build.sbt +++ b/build.sbt @@ -3,7 +3,7 @@ import Dependencies.ProjectOps lazy val criteria4s: Project = project .in(file(".")) - .disablePlugins(AssemblyPlugin) + .disablePlugins(Build, AssemblyPlugin, HeaderPlugin) .aggregate(core, sql, mongodb, examples) .settings( name := "criteria4s" diff --git a/core/src/main/scala/com/eff3ct/criteria4s/core/Conjuction.scala b/core/src/main/scala/com/eff3ct/criteria4s/core/Conjuction.scala new file mode 100644 index 0000000..909d043 --- /dev/null +++ b/core/src/main/scala/com/eff3ct/criteria4s/core/Conjuction.scala @@ -0,0 +1,71 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.core + +import com.eff3ct.criteria4s.core +import com.eff3ct.criteria4s.core.Criteria._ +import com.eff3ct.criteria4s.instances.builder._ + +trait ConjuctionBinary[T <: CriteriaTag] { + def eval(cr1: Criteria[T], cr2: Criteria[T]): Criteria[T] +} + +trait ConjuctionUnary[T <: CriteriaTag] { + def eval(cr: Criteria[T]): Criteria[T] +} + +object ConjuctionBinary { + + def eval[T <: CriteriaTag](cr1: Criteria[T], cr2: Criteria[T])(implicit + ev: ConjuctionBinary[T] + ): Criteria[T] = + ev.eval(cr1, cr2) + + trait OR[T <: CriteriaTag] extends ConjuctionBinary[T] + + trait AND[T <: CriteriaTag] extends ConjuctionBinary[T] + + implicit val orBuilder: BuilderBinary[OR] = new BuilderBinary[OR] { + override def build[T <: CriteriaTag](F: (String, String) => String): OR[T] = + (cr1: Criteria[T], cr2: Criteria[T]) => pure(F(cr1.value, cr2.value)) + } + + implicit val andBuilder: BuilderBinary[AND] = new BuilderBinary[AND] { + override def build[T <: CriteriaTag](F: (String, String) => String): AND[T] = + (cr1: Criteria[T], cr2: Criteria[T]) => pure(F(cr1.value, cr2.value)) + } + +} + +object ConjuctionUnary { + + trait NOT[T <: CriteriaTag] extends ConjuctionUnary[T] + + implicit val notBuilder: BuilderUnary[NOT] = new BuilderUnary[NOT] { + override def build[T <: core.CriteriaTag](F: String => String): NOT[T] = + (cr: Criteria[T]) => pure(F(cr.value)) + } + +} diff --git a/core/src/main/scala/com/eff3ct/criteria4s/core/Criteria.scala b/core/src/main/scala/com/eff3ct/criteria4s/core/Criteria.scala new file mode 100644 index 0000000..b985db8 --- /dev/null +++ b/core/src/main/scala/com/eff3ct/criteria4s/core/Criteria.scala @@ -0,0 +1,39 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.core + +trait Criteria[T <: CriteriaTag] { + def value: String + + override def toString: String = value +} + +object Criteria { + def pure[T <: CriteriaTag](v: String): Criteria[T] = new Criteria[T] { + + override def value: String = v + } + private[core] trait CriteriaTag +} diff --git a/core/src/main/scala/io/github/rafafrdz/criteria4s/core/Predicate.scala b/core/src/main/scala/com/eff3ct/criteria4s/core/Predicate.scala similarity index 82% rename from core/src/main/scala/io/github/rafafrdz/criteria4s/core/Predicate.scala rename to core/src/main/scala/com/eff3ct/criteria4s/core/Predicate.scala index e3dfdfb..58fe04f 100644 --- a/core/src/main/scala/io/github/rafafrdz/criteria4s/core/Predicate.scala +++ b/core/src/main/scala/com/eff3ct/criteria4s/core/Predicate.scala @@ -1,7 +1,31 @@ -package io.github.rafafrdz.criteria4s.core - -import io.github.rafafrdz.criteria4s.core.Criteria._ -import io.github.rafafrdz.criteria4s.instances.builder.{BuilderBinary, BuilderUnary} +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.core + +import com.eff3ct.criteria4s.core.Criteria._ +import com.eff3ct.criteria4s.instances.builder.{BuilderBinary, BuilderUnary} sealed trait Predicate[T <: CriteriaTag] diff --git a/core/src/main/scala/io/github/rafafrdz/criteria4s/core/Ref.scala b/core/src/main/scala/com/eff3ct/criteria4s/core/Ref.scala similarity index 53% rename from core/src/main/scala/io/github/rafafrdz/criteria4s/core/Ref.scala rename to core/src/main/scala/com/eff3ct/criteria4s/core/Ref.scala index 741b439..3b9c722 100644 --- a/core/src/main/scala/io/github/rafafrdz/criteria4s/core/Ref.scala +++ b/core/src/main/scala/com/eff3ct/criteria4s/core/Ref.scala @@ -1,4 +1,28 @@ -package io.github.rafafrdz.criteria4s.core +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.core sealed trait Ref[D <: CriteriaTag, V] { def asString(implicit show: Show[V, D]): String diff --git a/core/src/main/scala/com/eff3ct/criteria4s/core/Show.scala b/core/src/main/scala/com/eff3ct/criteria4s/core/Show.scala new file mode 100644 index 0000000..63927f5 --- /dev/null +++ b/core/src/main/scala/com/eff3ct/criteria4s/core/Show.scala @@ -0,0 +1,36 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.core + +trait Show[-V, D <: CriteriaTag] { + def show(v: V): String +} + +object Show { + def create[V, D <: CriteriaTag](f: V => String): Show[V, D] = (v: V) => f(v) + + implicit def defaultStringShow[D <: CriteriaTag]: Show[String, D] = identity + implicit def defaultIntShow[V <: AnyVal, D <: CriteriaTag]: Show[V, D] = create(_.toString) +} diff --git a/core/src/main/scala/com/eff3ct/criteria4s/core/package.scala b/core/src/main/scala/com/eff3ct/criteria4s/core/package.scala new file mode 100644 index 0000000..c305e73 --- /dev/null +++ b/core/src/main/scala/com/eff3ct/criteria4s/core/package.scala @@ -0,0 +1,63 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s + +package object core { + + type CriteriaTag = Criteria.CriteriaTag + + type AND[T <: CriteriaTag] = ConjuctionBinary.AND[T] + + type OR[T <: CriteriaTag] = ConjuctionBinary.OR[T] + + type NOT[T <: CriteriaTag] = ConjuctionUnary.NOT[T] + + type GT[T <: CriteriaTag] = PredicateBinary.GT[T] + + type LT[T <: CriteriaTag] = PredicateBinary.LT[T] + + type EQ[T <: CriteriaTag] = PredicateBinary.EQ[T] + + type NEQ[T <: CriteriaTag] = PredicateBinary.NEQ[T] + + type GEQ[T <: CriteriaTag] = PredicateBinary.GEQ[T] + + type LEQ[T <: CriteriaTag] = PredicateBinary.LEQ[T] + + type LIKE[T <: CriteriaTag] = PredicateBinary.LIKE[T] + + type IN[T <: CriteriaTag] = PredicateBinary.IN[T] + + type NOTIN[T <: CriteriaTag] = PredicateBinary.NOTIN[T] + + type ISNULL[T <: CriteriaTag] = PredicateUnary.ISNULL[T] + + type ISNOTNULL[T <: CriteriaTag] = PredicateUnary.ISNOTNULL[T] + + type BETWEEN[T <: CriteriaTag] = PredicateBinary.BETWEEN[T] + + type NOTBETWEEN[T <: CriteriaTag] = PredicateBinary.NOTBETWEEN[T] + +} diff --git a/core/src/main/scala/com/eff3ct/criteria4s/extensions/conjunctions.scala b/core/src/main/scala/com/eff3ct/criteria4s/extensions/conjunctions.scala new file mode 100644 index 0000000..d31d743 --- /dev/null +++ b/core/src/main/scala/com/eff3ct/criteria4s/extensions/conjunctions.scala @@ -0,0 +1,41 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.extensions + +import com.eff3ct.criteria4s.{functions => F} +import com.eff3ct.criteria4s.core._ + +trait conjunctions { + + implicit class CriteriaOpsImplicit[T <: CriteriaTag](c: Criteria[T]) { + def and(other: Criteria[T])(implicit H: AND[T]): Criteria[T] = F.and(c, other) + def &&(other: Criteria[T])(implicit H: AND[T]): Criteria[T] = F.and(c, other) + def or(other: Criteria[T])(implicit H: OR[T]): Criteria[T] = F.or(c, other) + def ||(other: Criteria[T])(implicit H: OR[T]): Criteria[T] = F.or(c, other) + } + +} + +object conjunctions extends conjunctions diff --git a/core/src/main/scala/com/eff3ct/criteria4s/extensions/package.scala b/core/src/main/scala/com/eff3ct/criteria4s/extensions/package.scala new file mode 100644 index 0000000..c3979d1 --- /dev/null +++ b/core/src/main/scala/com/eff3ct/criteria4s/extensions/package.scala @@ -0,0 +1,27 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s + +package object extensions extends conjunctions with predicates diff --git a/core/src/main/scala/io/github/rafafrdz/criteria4s/extensions/predicates.scala b/core/src/main/scala/com/eff3ct/criteria4s/extensions/predicates.scala similarity index 56% rename from core/src/main/scala/io/github/rafafrdz/criteria4s/extensions/predicates.scala rename to core/src/main/scala/com/eff3ct/criteria4s/extensions/predicates.scala index 0ddcd4a..9c961b0 100644 --- a/core/src/main/scala/io/github/rafafrdz/criteria4s/extensions/predicates.scala +++ b/core/src/main/scala/com/eff3ct/criteria4s/extensions/predicates.scala @@ -1,10 +1,34 @@ -package io.github.rafafrdz.criteria4s.extensions +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ -import io.github.rafafrdz.criteria4s.{functions => F} -import io.github.rafafrdz.criteria4s.core.{Criteria, CriteriaTag, Ref, Show} -import io.github.rafafrdz.criteria4s.core.PredicateBinary._ -import io.github.rafafrdz.criteria4s.core.PredicateUnary._ -import io.github.rafafrdz.criteria4s.core.Ref.Collection +package com.eff3ct.criteria4s.extensions + +import com.eff3ct.criteria4s.{functions => F} +import com.eff3ct.criteria4s.core.{Criteria, CriteriaTag, Ref, Show} +import com.eff3ct.criteria4s.core.PredicateBinary._ +import com.eff3ct.criteria4s.core.PredicateUnary._ +import com.eff3ct.criteria4s.core.Ref.Collection trait predicates { diff --git a/core/src/main/scala/com/eff3ct/criteria4s/functions/conjunctions.scala b/core/src/main/scala/com/eff3ct/criteria4s/functions/conjunctions.scala new file mode 100644 index 0000000..ec56e64 --- /dev/null +++ b/core/src/main/scala/com/eff3ct/criteria4s/functions/conjunctions.scala @@ -0,0 +1,49 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.functions + +import com.eff3ct.criteria4s.core._ + +private[functions] trait conjunctions { + + def and[T <: CriteriaTag: AND](cr1: Criteria[T], cr2: Criteria[T]): Criteria[T] = + cond[T, AND[T]](cr1, cr2) + + def &&[T <: CriteriaTag: AND](cr1: Criteria[T], cr2: Criteria[T]): Criteria[T] = + and(cr1, cr2) + + def or[T <: CriteriaTag: OR](cr1: Criteria[T], cr2: Criteria[T]): Criteria[T] = + cond[T, OR[T]](cr1, cr2) + + def ||[T <: CriteriaTag: OR](cr1: Criteria[T], cr2: Criteria[T]): Criteria[T] = + or(cr1, cr2) + + def not[T <: CriteriaTag: NOT](cr: Criteria[T]): Criteria[T] = + cond[T, NOT[T]](cr) + + def !![T <: CriteriaTag: NOT](cr: Criteria[T]): Criteria[T] = not(cr) + +} +object conjunctions extends conjunctions diff --git a/core/src/main/scala/com/eff3ct/criteria4s/functions/package.scala b/core/src/main/scala/com/eff3ct/criteria4s/functions/package.scala new file mode 100644 index 0000000..71f13ea --- /dev/null +++ b/core/src/main/scala/com/eff3ct/criteria4s/functions/package.scala @@ -0,0 +1,54 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s + +import com.eff3ct.criteria4s.core._ + +package object functions extends predicates with conjunctions { + + def pred[T <: CriteriaTag, H <: PredicateBinary[T], L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit + H: H, + showL: Show[L, T], + showR: Show[R, T] + ): Criteria[T] = + H.eval(cr1, cr2) + + def pred[T <: CriteriaTag, H <: PredicateUnary[T], V](ref: Ref[T, V])(implicit + H: H, + show: Show[V, T] + ): Criteria[T] = + H.eval(ref) + + def cond[T <: CriteriaTag, H <: ConjuctionBinary[T]](cr1: Criteria[T], cr2: Criteria[T])(implicit + H: H + ): Criteria[T] = + H.eval(cr1, cr2) + + def cond[T <: CriteriaTag, H <: ConjuctionUnary[T]](cr: Criteria[T])(implicit + H: H + ): Criteria[T] = + H.eval(cr) + +} diff --git a/core/src/main/scala/io/github/rafafrdz/criteria4s/functions/predicates.scala b/core/src/main/scala/com/eff3ct/criteria4s/functions/predicates.scala similarity index 68% rename from core/src/main/scala/io/github/rafafrdz/criteria4s/functions/predicates.scala rename to core/src/main/scala/com/eff3ct/criteria4s/functions/predicates.scala index 7ef4c42..c8a87fd 100644 --- a/core/src/main/scala/io/github/rafafrdz/criteria4s/functions/predicates.scala +++ b/core/src/main/scala/com/eff3ct/criteria4s/functions/predicates.scala @@ -1,9 +1,33 @@ -package io.github.rafafrdz.criteria4s.functions - -import io.github.rafafrdz.criteria4s.core.{Column, Criteria, CriteriaTag, Ref, Show} -import io.github.rafafrdz.criteria4s.core.PredicateBinary._ -import io.github.rafafrdz.criteria4s.core.PredicateUnary._ -import io.github.rafafrdz.criteria4s.core.Ref._ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.functions + +import com.eff3ct.criteria4s.core.{Column, Criteria, CriteriaTag, Ref, Show} +import com.eff3ct.criteria4s.core.PredicateBinary._ +import com.eff3ct.criteria4s.core.PredicateUnary._ +import com.eff3ct.criteria4s.core.Ref._ private[functions] trait predicates { diff --git a/core/src/main/scala/com/eff3ct/criteria4s/instances/builder/BuilderBinary.scala b/core/src/main/scala/com/eff3ct/criteria4s/instances/builder/BuilderBinary.scala new file mode 100644 index 0000000..fca1595 --- /dev/null +++ b/core/src/main/scala/com/eff3ct/criteria4s/instances/builder/BuilderBinary.scala @@ -0,0 +1,31 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.instances.builder + +import com.eff3ct.criteria4s.core.CriteriaTag + +trait BuilderBinary[H[_ <: CriteriaTag]] { + def build[T <: CriteriaTag](F: (String, String) => String): H[T] +} diff --git a/core/src/main/scala/com/eff3ct/criteria4s/instances/builder/BuilderUnary.scala b/core/src/main/scala/com/eff3ct/criteria4s/instances/builder/BuilderUnary.scala new file mode 100644 index 0000000..fa79487 --- /dev/null +++ b/core/src/main/scala/com/eff3ct/criteria4s/instances/builder/BuilderUnary.scala @@ -0,0 +1,31 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.instances.builder + +import com.eff3ct.criteria4s.core.CriteriaTag + +trait BuilderUnary[H[_ <: CriteriaTag]] { + def build[T <: CriteriaTag](F: String => String): H[T] +} diff --git a/core/src/main/scala/com/eff3ct/criteria4s/instances/package.scala b/core/src/main/scala/com/eff3ct/criteria4s/instances/package.scala new file mode 100644 index 0000000..4bd7cf7 --- /dev/null +++ b/core/src/main/scala/com/eff3ct/criteria4s/instances/package.scala @@ -0,0 +1,40 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s + +import com.eff3ct.criteria4s.core.CriteriaTag +import com.eff3ct.criteria4s.instances.builder.{BuilderBinary, BuilderUnary} + +package object instances { + def build[T <: CriteriaTag, H[_ <: CriteriaTag]](F: (String, String) => String)(implicit + BH: BuilderBinary[H] + ): H[T] = + BH.build(F) + + def build[T <: CriteriaTag, H[_ <: CriteriaTag]](F: String => String)(implicit + BH: BuilderUnary[H] + ): H[T] = + BH.build(F) +} diff --git a/core/src/main/scala/io/github/rafafrdz/criteria4s/core/Conjuction.scala b/core/src/main/scala/io/github/rafafrdz/criteria4s/core/Conjuction.scala deleted file mode 100644 index dc70ae7..0000000 --- a/core/src/main/scala/io/github/rafafrdz/criteria4s/core/Conjuction.scala +++ /dev/null @@ -1,47 +0,0 @@ -package io.github.rafafrdz.criteria4s.core - -import io.github.rafafrdz.criteria4s.core -import io.github.rafafrdz.criteria4s.core.Criteria._ -import io.github.rafafrdz.criteria4s.instances.builder._ - -trait ConjuctionBinary[T <: CriteriaTag] { - def eval(cr1: Criteria[T], cr2: Criteria[T]): Criteria[T] -} - -trait ConjuctionUnary[T <: CriteriaTag] { - def eval(cr: Criteria[T]): Criteria[T] -} - -object ConjuctionBinary { - - def eval[T <: CriteriaTag](cr1: Criteria[T], cr2: Criteria[T])(implicit - ev: ConjuctionBinary[T] - ): Criteria[T] = - ev.eval(cr1, cr2) - - trait OR[T <: CriteriaTag] extends ConjuctionBinary[T] - - trait AND[T <: CriteriaTag] extends ConjuctionBinary[T] - - implicit val orBuilder: BuilderBinary[OR] = new BuilderBinary[OR] { - override def build[T <: CriteriaTag](F: (String, String) => String): OR[T] = - (cr1: Criteria[T], cr2: Criteria[T]) => pure(F(cr1.value, cr2.value)) - } - - implicit val andBuilder: BuilderBinary[AND] = new BuilderBinary[AND] { - override def build[T <: CriteriaTag](F: (String, String) => String): AND[T] = - (cr1: Criteria[T], cr2: Criteria[T]) => pure(F(cr1.value, cr2.value)) - } - -} - -object ConjuctionUnary { - - trait NOT[T <: CriteriaTag] extends ConjuctionUnary[T] - - implicit val notBuilder: BuilderUnary[NOT] = new BuilderUnary[NOT] { - override def build[T <: core.CriteriaTag](F: String => String): NOT[T] = - (cr: Criteria[T]) => pure(F(cr.value)) - } - -} diff --git a/core/src/main/scala/io/github/rafafrdz/criteria4s/core/Criteria.scala b/core/src/main/scala/io/github/rafafrdz/criteria4s/core/Criteria.scala deleted file mode 100644 index 272d1df..0000000 --- a/core/src/main/scala/io/github/rafafrdz/criteria4s/core/Criteria.scala +++ /dev/null @@ -1,15 +0,0 @@ -package io.github.rafafrdz.criteria4s.core - -trait Criteria[T <: CriteriaTag] { - def value: String - - override def toString: String = value -} - -object Criteria { - def pure[T <: CriteriaTag](v: String): Criteria[T] = new Criteria[T] { - - override def value: String = v - } - private[core] trait CriteriaTag -} diff --git a/core/src/main/scala/io/github/rafafrdz/criteria4s/core/Show.scala b/core/src/main/scala/io/github/rafafrdz/criteria4s/core/Show.scala deleted file mode 100644 index 0edecde..0000000 --- a/core/src/main/scala/io/github/rafafrdz/criteria4s/core/Show.scala +++ /dev/null @@ -1,12 +0,0 @@ -package io.github.rafafrdz.criteria4s.core - -trait Show[-V, D <: CriteriaTag] { - def show(v: V): String -} - -object Show { - def create[V, D <: CriteriaTag](f: V => String): Show[V, D] = (v: V) => f(v) - - implicit def defaultStringShow[D <: CriteriaTag]: Show[String, D] = identity - implicit def defaultIntShow[V <: AnyVal, D <: CriteriaTag]: Show[V, D] = create(_.toString) -} diff --git a/core/src/main/scala/io/github/rafafrdz/criteria4s/core/package.scala b/core/src/main/scala/io/github/rafafrdz/criteria4s/core/package.scala deleted file mode 100644 index 5534041..0000000 --- a/core/src/main/scala/io/github/rafafrdz/criteria4s/core/package.scala +++ /dev/null @@ -1,39 +0,0 @@ -package io.github.rafafrdz.criteria4s - -package object core { - - type CriteriaTag = Criteria.CriteriaTag - - type AND[T <: CriteriaTag] = ConjuctionBinary.AND[T] - - type OR[T <: CriteriaTag] = ConjuctionBinary.OR[T] - - type NOT[T <: CriteriaTag] = ConjuctionUnary.NOT[T] - - type GT[T <: CriteriaTag] = PredicateBinary.GT[T] - - type LT[T <: CriteriaTag] = PredicateBinary.LT[T] - - type EQ[T <: CriteriaTag] = PredicateBinary.EQ[T] - - type NEQ[T <: CriteriaTag] = PredicateBinary.NEQ[T] - - type GEQ[T <: CriteriaTag] = PredicateBinary.GEQ[T] - - type LEQ[T <: CriteriaTag] = PredicateBinary.LEQ[T] - - type LIKE[T <: CriteriaTag] = PredicateBinary.LIKE[T] - - type IN[T <: CriteriaTag] = PredicateBinary.IN[T] - - type NOTIN[T <: CriteriaTag] = PredicateBinary.NOTIN[T] - - type ISNULL[T <: CriteriaTag] = PredicateUnary.ISNULL[T] - - type ISNOTNULL[T <: CriteriaTag] = PredicateUnary.ISNOTNULL[T] - - type BETWEEN[T <: CriteriaTag] = PredicateBinary.BETWEEN[T] - - type NOTBETWEEN[T <: CriteriaTag] = PredicateBinary.NOTBETWEEN[T] - -} diff --git a/core/src/main/scala/io/github/rafafrdz/criteria4s/extensions/conjunctions.scala b/core/src/main/scala/io/github/rafafrdz/criteria4s/extensions/conjunctions.scala deleted file mode 100644 index fefb08b..0000000 --- a/core/src/main/scala/io/github/rafafrdz/criteria4s/extensions/conjunctions.scala +++ /dev/null @@ -1,17 +0,0 @@ -package io.github.rafafrdz.criteria4s.extensions - -import io.github.rafafrdz.criteria4s.{functions => F} -import io.github.rafafrdz.criteria4s.core._ - -trait conjunctions { - - implicit class CriteriaOpsImplicit[T <: CriteriaTag](c: Criteria[T]) { - def and(other: Criteria[T])(implicit H: AND[T]): Criteria[T] = F.and(c, other) - def &&(other: Criteria[T])(implicit H: AND[T]): Criteria[T] = F.and(c, other) - def or(other: Criteria[T])(implicit H: OR[T]): Criteria[T] = F.or(c, other) - def ||(other: Criteria[T])(implicit H: OR[T]): Criteria[T] = F.or(c, other) - } - -} - -object conjunctions extends conjunctions diff --git a/core/src/main/scala/io/github/rafafrdz/criteria4s/extensions/package.scala b/core/src/main/scala/io/github/rafafrdz/criteria4s/extensions/package.scala deleted file mode 100644 index d155eae..0000000 --- a/core/src/main/scala/io/github/rafafrdz/criteria4s/extensions/package.scala +++ /dev/null @@ -1,3 +0,0 @@ -package io.github.rafafrdz.criteria4s - -package object extensions extends conjunctions with predicates diff --git a/core/src/main/scala/io/github/rafafrdz/criteria4s/functions/conjunctions.scala b/core/src/main/scala/io/github/rafafrdz/criteria4s/functions/conjunctions.scala deleted file mode 100644 index 3ae3057..0000000 --- a/core/src/main/scala/io/github/rafafrdz/criteria4s/functions/conjunctions.scala +++ /dev/null @@ -1,25 +0,0 @@ -package io.github.rafafrdz.criteria4s.functions - -import io.github.rafafrdz.criteria4s.core._ - -private[functions] trait conjunctions { - - def and[T <: CriteriaTag: AND](cr1: Criteria[T], cr2: Criteria[T]): Criteria[T] = - cond[T, AND[T]](cr1, cr2) - - def &&[T <: CriteriaTag: AND](cr1: Criteria[T], cr2: Criteria[T]): Criteria[T] = - and(cr1, cr2) - - def or[T <: CriteriaTag: OR](cr1: Criteria[T], cr2: Criteria[T]): Criteria[T] = - cond[T, OR[T]](cr1, cr2) - - def ||[T <: CriteriaTag: OR](cr1: Criteria[T], cr2: Criteria[T]): Criteria[T] = - or(cr1, cr2) - - def not[T <: CriteriaTag: NOT](cr: Criteria[T]): Criteria[T] = - cond[T, NOT[T]](cr) - - def !![T <: CriteriaTag: NOT](cr: Criteria[T]): Criteria[T] = not(cr) - -} -object conjunctions extends conjunctions diff --git a/core/src/main/scala/io/github/rafafrdz/criteria4s/functions/package.scala b/core/src/main/scala/io/github/rafafrdz/criteria4s/functions/package.scala deleted file mode 100644 index 2d43ae4..0000000 --- a/core/src/main/scala/io/github/rafafrdz/criteria4s/functions/package.scala +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.rafafrdz.criteria4s - -import io.github.rafafrdz.criteria4s.core._ - -package object functions extends predicates with conjunctions { - - def pred[T <: CriteriaTag, H <: PredicateBinary[T], L, R](cr1: Ref[T, L], cr2: Ref[T, R])(implicit - H: H, - showL: Show[L, T], - showR: Show[R, T] - ): Criteria[T] = - H.eval(cr1, cr2) - - def pred[T <: CriteriaTag, H <: PredicateUnary[T], V](ref: Ref[T, V])(implicit - H: H, - show: Show[V, T] - ): Criteria[T] = - H.eval(ref) - - def cond[T <: CriteriaTag, H <: ConjuctionBinary[T]](cr1: Criteria[T], cr2: Criteria[T])(implicit - H: H - ): Criteria[T] = - H.eval(cr1, cr2) - - def cond[T <: CriteriaTag, H <: ConjuctionUnary[T]](cr: Criteria[T])(implicit - H: H - ): Criteria[T] = - H.eval(cr) - -} diff --git a/core/src/main/scala/io/github/rafafrdz/criteria4s/instances/builder/BuilderBinary.scala b/core/src/main/scala/io/github/rafafrdz/criteria4s/instances/builder/BuilderBinary.scala deleted file mode 100644 index 012fd7c..0000000 --- a/core/src/main/scala/io/github/rafafrdz/criteria4s/instances/builder/BuilderBinary.scala +++ /dev/null @@ -1,7 +0,0 @@ -package io.github.rafafrdz.criteria4s.instances.builder - -import io.github.rafafrdz.criteria4s.core.CriteriaTag - -trait BuilderBinary[H[_ <: CriteriaTag]] { - def build[T <: CriteriaTag](F: (String, String) => String): H[T] -} diff --git a/core/src/main/scala/io/github/rafafrdz/criteria4s/instances/builder/BuilderUnary.scala b/core/src/main/scala/io/github/rafafrdz/criteria4s/instances/builder/BuilderUnary.scala deleted file mode 100644 index 323d52d..0000000 --- a/core/src/main/scala/io/github/rafafrdz/criteria4s/instances/builder/BuilderUnary.scala +++ /dev/null @@ -1,7 +0,0 @@ -package io.github.rafafrdz.criteria4s.instances.builder - -import io.github.rafafrdz.criteria4s.core.CriteriaTag - -trait BuilderUnary[H[_ <: CriteriaTag]] { - def build[T <: CriteriaTag](F: String => String): H[T] -} diff --git a/core/src/main/scala/io/github/rafafrdz/criteria4s/instances/package.scala b/core/src/main/scala/io/github/rafafrdz/criteria4s/instances/package.scala deleted file mode 100644 index 7e930d9..0000000 --- a/core/src/main/scala/io/github/rafafrdz/criteria4s/instances/package.scala +++ /dev/null @@ -1,16 +0,0 @@ -package io.github.rafafrdz.criteria4s - -import io.github.rafafrdz.criteria4s.core.CriteriaTag -import io.github.rafafrdz.criteria4s.instances.builder.{BuilderBinary, BuilderUnary} - -package object instances { - def build[T <: CriteriaTag, H[_ <: CriteriaTag]](F: (String, String) => String)(implicit - BH: BuilderBinary[H] - ): H[T] = - BH.build(F) - - def build[T <: CriteriaTag, H[_ <: CriteriaTag]](F: String => String)(implicit - BH: BuilderUnary[H] - ): H[T] = - BH.build(F) -} diff --git a/doc/formal-definition.md b/doc/formal-definition.md new file mode 100644 index 0000000..464b385 --- /dev/null +++ b/doc/formal-definition.md @@ -0,0 +1,22 @@ +## Formal Definition of the Expressions + +The formal definition of the Criteria4s' type-classes (expressions) is as follows: + +```text +Criteria := Conjuction Criteria Criteria | Predicate | Value +Predicate := UnaryPred Ref | BinaryPred Ref Ref +Ref := Value | Col +Conjuction := AND | OR +UnaryPred := IS_NULL | IS_NOT_NULL ... +BinaryPred := EQ | NEQ | GT | LT | GEQ | LEQ | IN | LIKE ... +``` + +Where: + +- `Criteria` is the main expression of the DSL +- `Conjuction` is the conjunction operator expression +- `UnaryPredOp` is the unary predicate operator expression +- `BinaryPredOp` is the binary predicate operator expression +- `Ref` is a reference to a value or a column +- `Value` is a value expression of a certain type `T` +- `Col` is a column expression \ No newline at end of file diff --git a/examples/src/main/scala/com/eff3ct/criteria4s/examples/ArraysExample.scala b/examples/src/main/scala/com/eff3ct/criteria4s/examples/ArraysExample.scala new file mode 100644 index 0000000..3dcdf6a --- /dev/null +++ b/examples/src/main/scala/com/eff3ct/criteria4s/examples/ArraysExample.scala @@ -0,0 +1,57 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.examples + +import com.eff3ct.criteria4s.core._ +import com.eff3ct.criteria4s.dialect.mongodb.MongoDB +import com.eff3ct.criteria4s.examples.datastores.{Postgres, WeirdDatastore} +import com.eff3ct.criteria4s.functions._ + +object ArraysExample extends App { + val aIsNull: Criteria[Postgres] = isNull(col("a")) + def aIsNullAlgebra[ + T <: CriteriaTag: ISNULL: Show[Column, *] + ]: Criteria[T] = isNull(col("a")) + + val numberInArray: Criteria[Postgres] = in(col("a"), array(1, 2, 3)) + def numberInArrayAlgebra[T <: CriteriaTag: IN: Show[Column, *]: Show[Seq[Int], *]]: Criteria[T] = + in(col("a"), array(1, 2, 3)) + + val combined: Criteria[Postgres] = or(aIsNull, numberInArray) + val moreCombined: Criteria[Postgres] = or(combined, ===(col("b"), lit(10))) + + println(aIsNull) + println(aIsNullAlgebra[Postgres]) + println(aIsNullAlgebra[WeirdDatastore]) + println(aIsNullAlgebra[MongoDB]) + + println(numberInArray) + println(numberInArrayAlgebra[Postgres]) + println(numberInArrayAlgebra[WeirdDatastore]) + println(numberInArrayAlgebra[MongoDB]) + + println(combined) + println(moreCombined) +} diff --git a/examples/src/main/scala/com/eff3ct/criteria4s/examples/BetweenExample.scala b/examples/src/main/scala/com/eff3ct/criteria4s/examples/BetweenExample.scala new file mode 100644 index 0000000..70c09bf --- /dev/null +++ b/examples/src/main/scala/com/eff3ct/criteria4s/examples/BetweenExample.scala @@ -0,0 +1,47 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.examples + +import com.eff3ct.criteria4s.core._ +import com.eff3ct.criteria4s.dialect.mongodb.MongoDB +import com.eff3ct.criteria4s.examples.datastores.{Postgres, WeirdDatastore} +import com.eff3ct.criteria4s.extensions._ +import com.eff3ct.criteria4s.functions._ + +object BetweenExample extends App { + val simpleBetween: Criteria[Postgres] = col[Postgres]("a").between(range(1, 10)) + val simpleNotBetween: Criteria[Postgres] = col[Postgres]("b").notBetween(range("A", "Z")) + + def taglessFinalBetweenExample[ + T <: CriteriaTag: BETWEEN: Show[Column, *]: Show[(Int, Int), *] + ]: Criteria[T] = + col[T]("column") between range(100, 150) + + println(simpleBetween) + println(simpleNotBetween) + println(taglessFinalBetweenExample[Postgres]) + println(taglessFinalBetweenExample[WeirdDatastore]) + println(taglessFinalBetweenExample[MongoDB]) +} diff --git a/examples/src/main/scala/com/eff3ct/criteria4s/examples/Example.scala b/examples/src/main/scala/com/eff3ct/criteria4s/examples/Example.scala new file mode 100644 index 0000000..869a031 --- /dev/null +++ b/examples/src/main/scala/com/eff3ct/criteria4s/examples/Example.scala @@ -0,0 +1,46 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.examples + +import com.eff3ct.criteria4s.core._ +import com.eff3ct.criteria4s.examples.datastores.Postgres +import com.eff3ct.criteria4s.functions._ + +object Example extends App { + + val d: Criteria[Postgres] = or(and(lt(col("a"), lit(3)), lt(col("b"), lit(4))), bool(true)) + + val example: Criteria[Postgres] = + or( + and( + lt(col("col1"), lit(3)), + geq(col("col2"), lit(4)) + ), + and(isNull(col("col3")), =!=(col("col4"), col("col5"))) + ) + + println(d) + println(example) +} diff --git a/examples/src/main/scala/com/eff3ct/criteria4s/examples/Example2.scala b/examples/src/main/scala/com/eff3ct/criteria4s/examples/Example2.scala new file mode 100644 index 0000000..c117e82 --- /dev/null +++ b/examples/src/main/scala/com/eff3ct/criteria4s/examples/Example2.scala @@ -0,0 +1,54 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.examples + +import com.eff3ct.criteria4s.core._ +import com.eff3ct.criteria4s.examples.datastores.Postgres +import com.eff3ct.criteria4s.extensions._ +import com.eff3ct.criteria4s.functions._ + +object Example2 extends App { + + val d: Criteria[Postgres] = or(and(lt(col("a"), lit(3)), lt(col("b"), lit(4))), bool(true)) + val d2: Criteria[Postgres] = col[Postgres]("a") leq lit(3) + val d3: Criteria[Postgres] = col[Postgres]("b") leq lit(4) + val d4: Criteria[Postgres] = and(d2, d3) + val d5: Criteria[Postgres] = col[Postgres]("c") === lit("c") + val d6: Criteria[Postgres] = or(d4, d5) + + val expr: Criteria[Postgres] = + (col[Postgres]("a") leq lit(3)) and + (col[Postgres]("b") leq lit(4)) or + (col[Postgres]("c") === lit("c")) + + val inlineExpr: Criteria[Postgres] = + (col[Postgres]("a") leq lit(3)) and (col[Postgres]("b") leq lit(4)) or (col[Postgres]( + "c" + ) === lit("c")) + + println(d6) + println(expr) + println(inlineExpr) +} diff --git a/examples/src/main/scala/com/eff3ct/criteria4s/examples/Example3.scala b/examples/src/main/scala/com/eff3ct/criteria4s/examples/Example3.scala new file mode 100644 index 0000000..de70dec --- /dev/null +++ b/examples/src/main/scala/com/eff3ct/criteria4s/examples/Example3.scala @@ -0,0 +1,66 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.examples + +import com.eff3ct.criteria4s.core._ +import com.eff3ct.criteria4s.dialect.mongodb.MongoDB +import com.eff3ct.criteria4s.examples.datastores.{Postgres, WeirdDatastore} +import com.eff3ct.criteria4s.functions._ + +object Example3 extends App { + + def example1[T <: CriteriaTag: LT: AND: OR: Show[Column, *]]: Criteria[T] = + or(and(lt(col("a"), lit(3)), lt(col("b"), lit(4))), bool(true)) + + def example2[T <: CriteriaTag: LT: AND: OR: GEQ: ISNULL: NEQ: Show[Column, *]]: Criteria[T] = + or( + and( + lt(col("col1"), lit(3)), + geq(col("col2"), lit(4)) + ), + and(isNull(col("col3")), =!=(col("col4"), col("col5"))) + ) + + println { + s"""Examples for Postgres instances + | + |example1[Postgres]: ${example1[Postgres]} + | + |example2[Postgres]: ${example2[Postgres]} + | + |Examples for WeirdDatastore instances + | + |example1[WeirdDatastore]: ${example1[WeirdDatastore]} + | + |example2[WeirdDatastore]: ${example2[WeirdDatastore]} + | + |Examples for MongoDB instances + | + |example1[MongoDB]: ${example1[MongoDB]} + | + |example2[MongoDB]: ${example2[MongoDB]} + |""".stripMargin + } +} diff --git a/examples/src/main/scala/com/eff3ct/criteria4s/examples/Example4.scala b/examples/src/main/scala/com/eff3ct/criteria4s/examples/Example4.scala new file mode 100644 index 0000000..990eece --- /dev/null +++ b/examples/src/main/scala/com/eff3ct/criteria4s/examples/Example4.scala @@ -0,0 +1,69 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.examples + +import com.eff3ct.criteria4s.core._ +import com.eff3ct.criteria4s.dialect.mongodb.MongoDB +import com.eff3ct.criteria4s.examples.datastores.{MySQL, Postgres, WeirdDatastore} +import com.eff3ct.criteria4s.extensions._ +import com.eff3ct.criteria4s.functions._ + +object Example4 extends App { + + def expr[T <: CriteriaTag: LEQ: EQ: AND: OR: Show[Column, *]]: Criteria[T] = + (col[T]("a") leq lit(3)) and + (col[T]("b") leq lit(4)) or + (col[T]("c") === lit("c")) + + def inlineExpr[T <: CriteriaTag: LEQ: EQ: AND: OR: Show[Column, *]]: Criteria[T] = + (col[T]("a") leq lit(3)) and (col[T]("b") leq lit(4)) or (col[T]("c") === lit("c")) + + println { + s"""Examples for Postgres instances + | + |expr[Postgres]: ${expr[Postgres]} + | + |inlineExpr[Postgres]: ${inlineExpr[Postgres]} + | + |Examples for MySQL instances + | + |expr[MySQL]: ${expr[MySQL]} + | + |inlineExpr[MySQL]: ${inlineExpr[MySQL]} + | + |Examples for WeirdDatastore instances + | + |expr[WeirdDatastore]: ${expr[WeirdDatastore]} + | + |inlineExpr[WeirdDatastore]: ${inlineExpr[WeirdDatastore]} + | + |Examples for MongoDB instances + | + |expr[MongoDB]: ${expr[MongoDB]} + | + |inlineExpr[MongoDB]: ${inlineExpr[MongoDB]} + |""".stripMargin + } +} diff --git a/examples/src/main/scala/com/eff3ct/criteria4s/examples/FilterByUserExample.scala b/examples/src/main/scala/com/eff3ct/criteria4s/examples/FilterByUserExample.scala new file mode 100644 index 0000000..ae23fd4 --- /dev/null +++ b/examples/src/main/scala/com/eff3ct/criteria4s/examples/FilterByUserExample.scala @@ -0,0 +1,59 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.examples + +import com.eff3ct.criteria4s.core._ +import com.eff3ct.criteria4s.dialect.mongodb.MongoDB +import com.eff3ct.criteria4s.examples.datastores.{MySQL, Postgres, WeirdDatastore} +import com.eff3ct.criteria4s.extensions._ +import com.eff3ct.criteria4s.functions._ + +import java.util.UUID + +object FilterByUserExample extends App { + + def expr[T <: CriteriaTag: EQ: Show[Column, *]](fieldName: String, id: UUID): Criteria[T] = + col[T](fieldName) === lit(id.toString) + + println { + s"""Examples for Postgres instances + | + |expr[Postgres]: ${expr[Postgres]("USER_ID", UUID.randomUUID())} + | + |Examples for MySQL instances + | + |expr[MySQL]: ${expr[MySQL]("USER_ID", UUID.randomUUID())} + | + |Examples for WeirdDatastore instances + | + |expr[WeirdDatastore]: ${expr[WeirdDatastore]("USER_ID", UUID.randomUUID())} + | + |Examples for MongoDB instances + | + |expr[MongoDB]: ${expr[MongoDB]("USER_ID", UUID.randomUUID())} + | + |""".stripMargin + } +} diff --git a/examples/src/main/scala/com/eff3ct/criteria4s/examples/NotExample.scala b/examples/src/main/scala/com/eff3ct/criteria4s/examples/NotExample.scala new file mode 100644 index 0000000..b1c5f43 --- /dev/null +++ b/examples/src/main/scala/com/eff3ct/criteria4s/examples/NotExample.scala @@ -0,0 +1,67 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.examples + +import com.eff3ct.criteria4s.core._ +import com.eff3ct.criteria4s.dialect.mongodb.MongoDB +import com.eff3ct.criteria4s.examples.datastores._ +import com.eff3ct.criteria4s.extensions._ +import com.eff3ct.criteria4s.functions._ + +object NotExample extends App { + + val simpleNot: Criteria[Postgres] = not(col[Postgres]("a").between(range(1, 10))) + + val symbolNot: Criteria[Postgres] = !!(col[Postgres]("a").between(range(1, 10))) + + def taglessFinalNotExample[ + T <: CriteriaTag: GT: NOT: Show[Column, *]: Show[(Int, Int), *] + ]: Criteria[T] = + not(col[T]("column") gt lit(100)) + + def taglessFinalNotSymbolExample[ + T <: CriteriaTag: BETWEEN: NOT: Show[Column, *]: Show[(Int, Int), *] + ]: Criteria[T] = + !!(col[T]("column") between range(100, 150)) + + def weirdExampleWithNot[ + T <: CriteriaTag: NOT: GT: LEQ: AND: Show[Column, *]: Show[(Int, Int), *] + ]: Criteria[T] = + not(col[T]("column") gt lit(2)) && (col[T]("column") leq lit(10)) + + println(simpleNot) + println(symbolNot) + println(taglessFinalNotExample[Postgres]) + println(taglessFinalNotExample[WeirdDatastore]) + println(taglessFinalNotExample[MongoDB]) + + println(taglessFinalNotSymbolExample[Postgres]) + println(taglessFinalNotSymbolExample[WeirdDatastore]) + println(taglessFinalNotSymbolExample[MongoDB]) + + println(weirdExampleWithNot[Postgres]) + println(weirdExampleWithNot[WeirdDatastore]) + println(weirdExampleWithNot[MongoDB]) +} diff --git a/examples/src/main/scala/com/eff3ct/criteria4s/examples/datastores/MySQL.scala b/examples/src/main/scala/com/eff3ct/criteria4s/examples/datastores/MySQL.scala new file mode 100644 index 0000000..7b0eb13 --- /dev/null +++ b/examples/src/main/scala/com/eff3ct/criteria4s/examples/datastores/MySQL.scala @@ -0,0 +1,44 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.examples.datastores + +import com.eff3ct.criteria4s.core.PredicateBinary._ +import com.eff3ct.criteria4s.core.{Column, Show} +import com.eff3ct.criteria4s.instances._ +import com.eff3ct.criteria4s.dialect.sql._ + +trait MySQL extends SQL + +object MySQL extends SQLExpr[MySQL] { + + /** + * That's not the right symbol for MySQL but it's just an example of how to override the default + * implementation + */ + implicit val showColumn: Show[Column, MySQL] = Show.create(_.colName) + + implicit override val leqPred: LEQ[MySQL] = build[MySQL, LEQ](predExpr("<<<")) + +} diff --git a/examples/src/main/scala/com/eff3ct/criteria4s/examples/datastores/Postgres.scala b/examples/src/main/scala/com/eff3ct/criteria4s/examples/datastores/Postgres.scala new file mode 100644 index 0000000..7bb78fb --- /dev/null +++ b/examples/src/main/scala/com/eff3ct/criteria4s/examples/datastores/Postgres.scala @@ -0,0 +1,43 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.examples.datastores + +import com.eff3ct.criteria4s.core.{Column, Show} +import com.eff3ct.criteria4s.dialect.sql.{SQL, _} + +trait Postgres extends SQL +object Postgres extends SQLExpr[Postgres] { + + /** + * That's not the right symbol for Postgres but it's just an example of how to override the + * default implementation + */ + + implicit val showColumn: Show[Column, Postgres] = Show.create(col => s"'${col.colName}'") + implicit def showSeq[T](implicit show: Show[T, Postgres]): Show[Seq[T], Postgres] = + Show.create(_.map(show.show).mkString("(", ", ", ")")) + implicit def betweenShow[T](implicit show: Show[T, Postgres]): Show[(T, T), Postgres] = + Show.create { case (l, r) => s"${show.show(l)} TO ${show.show(r)}" } +} diff --git a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/datastores/WeirdDatastore.scala b/examples/src/main/scala/com/eff3ct/criteria4s/examples/datastores/WeirdDatastore.scala similarity index 64% rename from examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/datastores/WeirdDatastore.scala rename to examples/src/main/scala/com/eff3ct/criteria4s/examples/datastores/WeirdDatastore.scala index 590590f..abd1552 100644 --- a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/datastores/WeirdDatastore.scala +++ b/examples/src/main/scala/com/eff3ct/criteria4s/examples/datastores/WeirdDatastore.scala @@ -1,7 +1,31 @@ -package io.github.rafafrdz.criteria4s.examples.datastores +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ -import io.github.rafafrdz.criteria4s.core._ -import io.github.rafafrdz.criteria4s.instances._ +package com.eff3ct.criteria4s.examples.datastores + +import com.eff3ct.criteria4s.core._ +import com.eff3ct.criteria4s.instances._ trait WeirdDatastore extends CriteriaTag diff --git a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/ArraysExample.scala b/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/ArraysExample.scala deleted file mode 100644 index ee8ba37..0000000 --- a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/ArraysExample.scala +++ /dev/null @@ -1,33 +0,0 @@ -package io.github.rafafrdz.criteria4s.examples - -import io.github.rafafrdz.criteria4s.core._ -import io.github.rafafrdz.criteria4s.dialect.mongodb.MongoDB -import io.github.rafafrdz.criteria4s.examples.datastores.{Postgres, WeirdDatastore} -import io.github.rafafrdz.criteria4s.functions._ - -object ArraysExample extends App { - val aIsNull: Criteria[Postgres] = isNull(col("a")) - def aIsNullAlgebra[ - T <: CriteriaTag: ISNULL: Show[Column, *] - ]: Criteria[T] = isNull(col("a")) - - val numberInArray: Criteria[Postgres] = in(col("a"), array(1, 2, 3)) - def numberInArrayAlgebra[T <: CriteriaTag: IN: Show[Column, *]: Show[Seq[Int], *]]: Criteria[T] = - in(col("a"), array(1, 2, 3)) - - val combined: Criteria[Postgres] = or(aIsNull, numberInArray) - val moreCombined: Criteria[Postgres] = or(combined, ===(col("b"), lit(10))) - - println(aIsNull) - println(aIsNullAlgebra[Postgres]) - println(aIsNullAlgebra[WeirdDatastore]) - println(aIsNullAlgebra[MongoDB]) - - println(numberInArray) - println(numberInArrayAlgebra[Postgres]) - println(numberInArrayAlgebra[WeirdDatastore]) - println(numberInArrayAlgebra[MongoDB]) - - println(combined) - println(moreCombined) -} diff --git a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/BetweenExample.scala b/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/BetweenExample.scala deleted file mode 100644 index 1cc6804..0000000 --- a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/BetweenExample.scala +++ /dev/null @@ -1,23 +0,0 @@ -package io.github.rafafrdz.criteria4s.examples - -import io.github.rafafrdz.criteria4s.core._ -import io.github.rafafrdz.criteria4s.dialect.mongodb.MongoDB -import io.github.rafafrdz.criteria4s.examples.datastores.{Postgres, WeirdDatastore} -import io.github.rafafrdz.criteria4s.extensions._ -import io.github.rafafrdz.criteria4s.functions._ - -object BetweenExample extends App { - val simpleBetween: Criteria[Postgres] = col[Postgres]("a").between(range(1, 10)) - val simpleNotBetween: Criteria[Postgres] = col[Postgres]("b").notBetween(range("A", "Z")) - - def taglessFinalBetweenExample[ - T <: CriteriaTag: BETWEEN: Show[Column, *]: Show[(Int, Int), *] - ]: Criteria[T] = - col[T]("column") between range(100, 150) - - println(simpleBetween) - println(simpleNotBetween) - println(taglessFinalBetweenExample[Postgres]) - println(taglessFinalBetweenExample[WeirdDatastore]) - println(taglessFinalBetweenExample[MongoDB]) -} diff --git a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/Example.scala b/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/Example.scala deleted file mode 100644 index f96f44e..0000000 --- a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/Example.scala +++ /dev/null @@ -1,22 +0,0 @@ -package io.github.rafafrdz.criteria4s.examples - -import io.github.rafafrdz.criteria4s.core._ -import io.github.rafafrdz.criteria4s.examples.datastores.Postgres -import io.github.rafafrdz.criteria4s.functions._ - -object Example extends App { - - val d: Criteria[Postgres] = or(and(lt(col("a"), lit(3)), lt(col("b"), lit(4))), bool(true)) - - val example: Criteria[Postgres] = - or( - and( - lt(col("col1"), lit(3)), - geq(col("col2"), lit(4)) - ), - and(isNull(col("col3")), =!=(col("col4"), col("col5"))) - ) - - println(d) - println(example) -} diff --git a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/Example2.scala b/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/Example2.scala deleted file mode 100644 index 01753f4..0000000 --- a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/Example2.scala +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.rafafrdz.criteria4s.examples - -import io.github.rafafrdz.criteria4s.core._ -import io.github.rafafrdz.criteria4s.examples.datastores.Postgres -import io.github.rafafrdz.criteria4s.extensions._ -import io.github.rafafrdz.criteria4s.functions._ - -object Example2 extends App { - - val d: Criteria[Postgres] = or(and(lt(col("a"), lit(3)), lt(col("b"), lit(4))), bool(true)) - val d2: Criteria[Postgres] = col[Postgres]("a") leq lit(3) - val d3: Criteria[Postgres] = col[Postgres]("b") leq lit(4) - val d4: Criteria[Postgres] = and(d2, d3) - val d5: Criteria[Postgres] = col[Postgres]("c") === lit("c") - val d6: Criteria[Postgres] = or(d4, d5) - - val expr: Criteria[Postgres] = - (col[Postgres]("a") leq lit(3)) and - (col[Postgres]("b") leq lit(4)) or - (col[Postgres]("c") === lit("c")) - - val inlineExpr: Criteria[Postgres] = - (col[Postgres]("a") leq lit(3)) and (col[Postgres]("b") leq lit(4)) or (col[Postgres]( - "c" - ) === lit("c")) - - println(d6) - println(expr) - println(inlineExpr) -} diff --git a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/Example3.scala b/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/Example3.scala deleted file mode 100644 index b56e74d..0000000 --- a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/Example3.scala +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.rafafrdz.criteria4s.examples - -import io.github.rafafrdz.criteria4s.core._ -import io.github.rafafrdz.criteria4s.dialect.mongodb.MongoDB -import io.github.rafafrdz.criteria4s.examples.datastores.{Postgres, WeirdDatastore} -import io.github.rafafrdz.criteria4s.functions._ - -object Example3 extends App { - - def example1[T <: CriteriaTag: LT: AND: OR: Show[Column, *]]: Criteria[T] = - or(and(lt(col("a"), lit(3)), lt(col("b"), lit(4))), bool(true)) - - def example2[T <: CriteriaTag: LT: AND: OR: GEQ: ISNULL: NEQ: Show[Column, *]]: Criteria[T] = - or( - and( - lt(col("col1"), lit(3)), - geq(col("col2"), lit(4)) - ), - and(isNull(col("col3")), =!=(col("col4"), col("col5"))) - ) - - println { - s"""Examples for Postgres instances - | - |example1[Postgres]: ${example1[Postgres]} - | - |example2[Postgres]: ${example2[Postgres]} - | - |Examples for WeirdDatastore instances - | - |example1[WeirdDatastore]: ${example1[WeirdDatastore]} - | - |example2[WeirdDatastore]: ${example2[WeirdDatastore]} - | - |Examples for MongoDB instances - | - |example1[MongoDB]: ${example1[MongoDB]} - | - |example2[MongoDB]: ${example2[MongoDB]} - |""".stripMargin - } -} diff --git a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/Example4.scala b/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/Example4.scala deleted file mode 100644 index 0fd5733..0000000 --- a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/Example4.scala +++ /dev/null @@ -1,45 +0,0 @@ -package io.github.rafafrdz.criteria4s.examples - -import io.github.rafafrdz.criteria4s.core._ -import io.github.rafafrdz.criteria4s.dialect.mongodb.MongoDB -import io.github.rafafrdz.criteria4s.examples.datastores.{MySQL, Postgres, WeirdDatastore} -import io.github.rafafrdz.criteria4s.extensions._ -import io.github.rafafrdz.criteria4s.functions._ - -object Example4 extends App { - - def expr[T <: CriteriaTag: LEQ: EQ: AND: OR: Show[Column, *]]: Criteria[T] = - (col[T]("a") leq lit(3)) and - (col[T]("b") leq lit(4)) or - (col[T]("c") === lit("c")) - - def inlineExpr[T <: CriteriaTag: LEQ: EQ: AND: OR: Show[Column, *]]: Criteria[T] = - (col[T]("a") leq lit(3)) and (col[T]("b") leq lit(4)) or (col[T]("c") === lit("c")) - - println { - s"""Examples for Postgres instances - | - |expr[Postgres]: ${expr[Postgres]} - | - |inlineExpr[Postgres]: ${inlineExpr[Postgres]} - | - |Examples for MySQL instances - | - |expr[MySQL]: ${expr[MySQL]} - | - |inlineExpr[MySQL]: ${inlineExpr[MySQL]} - | - |Examples for WeirdDatastore instances - | - |expr[WeirdDatastore]: ${expr[WeirdDatastore]} - | - |inlineExpr[WeirdDatastore]: ${inlineExpr[WeirdDatastore]} - | - |Examples for MongoDB instances - | - |expr[MongoDB]: ${expr[MongoDB]} - | - |inlineExpr[MongoDB]: ${inlineExpr[MongoDB]} - |""".stripMargin - } -} diff --git a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/FilterByUserExample.scala b/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/FilterByUserExample.scala deleted file mode 100644 index 1838830..0000000 --- a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/FilterByUserExample.scala +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.rafafrdz.criteria4s.examples - -import io.github.rafafrdz.criteria4s.core._ -import io.github.rafafrdz.criteria4s.dialect.mongodb.MongoDB -import io.github.rafafrdz.criteria4s.examples.datastores.{MySQL, Postgres, WeirdDatastore} -import io.github.rafafrdz.criteria4s.extensions._ -import io.github.rafafrdz.criteria4s.functions._ - -import java.util.UUID - -object FilterByUserExample extends App { - - def expr[T <: CriteriaTag: EQ: Show[Column, *]](fieldName: String, id: UUID): Criteria[T] = - col[T](fieldName) === lit(id.toString) - - println { - s"""Examples for Postgres instances - | - |expr[Postgres]: ${expr[Postgres]("USER_ID", UUID.randomUUID())} - | - |Examples for MySQL instances - | - |expr[MySQL]: ${expr[MySQL]("USER_ID", UUID.randomUUID())} - | - |Examples for WeirdDatastore instances - | - |expr[WeirdDatastore]: ${expr[WeirdDatastore]("USER_ID", UUID.randomUUID())} - | - |Examples for MongoDB instances - | - |expr[MongoDB]: ${expr[MongoDB]("USER_ID", UUID.randomUUID())} - | - |""".stripMargin - } -} diff --git a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/NotExample.scala b/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/NotExample.scala deleted file mode 100644 index 8432b45..0000000 --- a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/NotExample.scala +++ /dev/null @@ -1,43 +0,0 @@ -package io.github.rafafrdz.criteria4s.examples - -import io.github.rafafrdz.criteria4s.core._ -import io.github.rafafrdz.criteria4s.dialect.mongodb.MongoDB -import io.github.rafafrdz.criteria4s.examples.datastores._ -import io.github.rafafrdz.criteria4s.extensions._ -import io.github.rafafrdz.criteria4s.functions._ - -object NotExample extends App { - - val simpleNot: Criteria[Postgres] = not(col[Postgres]("a").between(range(1, 10))) - - val symbolNot: Criteria[Postgres] = !!(col[Postgres]("a").between(range(1, 10))) - - def taglessFinalNotExample[ - T <: CriteriaTag: GT: NOT: Show[Column, *]: Show[(Int, Int), *] - ]: Criteria[T] = - not(col[T]("column") gt lit(100)) - - def taglessFinalNotSymbolExample[ - T <: CriteriaTag: BETWEEN: NOT: Show[Column, *]: Show[(Int, Int), *] - ]: Criteria[T] = - !!(col[T]("column") between range(100, 150)) - - def weirdExampleWithNot[ - T <: CriteriaTag: NOT: GT: LEQ: AND: Show[Column, *]: Show[(Int, Int), *] - ]: Criteria[T] = - not(col[T]("column") gt lit(2)) && (col[T]("column") leq lit(10)) - - println(simpleNot) - println(symbolNot) - println(taglessFinalNotExample[Postgres]) - println(taglessFinalNotExample[WeirdDatastore]) - println(taglessFinalNotExample[MongoDB]) - - println(taglessFinalNotSymbolExample[Postgres]) - println(taglessFinalNotSymbolExample[WeirdDatastore]) - println(taglessFinalNotSymbolExample[MongoDB]) - - println(weirdExampleWithNot[Postgres]) - println(weirdExampleWithNot[WeirdDatastore]) - println(weirdExampleWithNot[MongoDB]) -} diff --git a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/datastores/MySQL.scala b/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/datastores/MySQL.scala deleted file mode 100644 index 0fd1460..0000000 --- a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/datastores/MySQL.scala +++ /dev/null @@ -1,20 +0,0 @@ -package io.github.rafafrdz.criteria4s.examples.datastores - -import io.github.rafafrdz.criteria4s.core.PredicateBinary._ -import io.github.rafafrdz.criteria4s.core.{Column, Show} -import io.github.rafafrdz.criteria4s.instances._ -import io.github.rafafrdz.criteria4s.dialect.sql._ - -trait MySQL extends SQL - -object MySQL extends SQLExpr[MySQL] { - - /** - * That's not the right symbol for MySQL but it's just an example of how to override the default - * implementation - */ - implicit val showColumn: Show[Column, MySQL] = Show.create(_.colName) - - implicit override val leqPred: LEQ[MySQL] = build[MySQL, LEQ](predExpr("<<<")) - -} diff --git a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/datastores/Postgres.scala b/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/datastores/Postgres.scala deleted file mode 100644 index 9b2eab3..0000000 --- a/examples/src/main/scala/io/github/rafafrdz/criteria4s/examples/datastores/Postgres.scala +++ /dev/null @@ -1,19 +0,0 @@ -package io.github.rafafrdz.criteria4s.examples.datastores - -import io.github.rafafrdz.criteria4s.core.{Column, Show} -import io.github.rafafrdz.criteria4s.dialect.sql.{SQL, _} - -trait Postgres extends SQL -object Postgres extends SQLExpr[Postgres] { - - /** - * That's not the right symbol for Postgres but it's just an example of how to override the - * default implementation - */ - - implicit val showColumn: Show[Column, Postgres] = Show.create(col => s"'${col.colName}'") - implicit def showSeq[T](implicit show: Show[T, Postgres]): Show[Seq[T], Postgres] = - Show.create(_.map(show.show).mkString("(", ", ", ")")) - implicit def betweenShow[T](implicit show: Show[T, Postgres]): Show[(T, T), Postgres] = - Show.create { case (l, r) => s"${show.show(l)} TO ${show.show(r)}" } -} diff --git a/mongodb/src/main/scala/io/github/rafafrdz/criteria4s/dialect/mongodb/MongoDB.scala b/mongodb/src/main/scala/com/eff3ct/criteria4s/dialect/mongodb/MongoDB.scala similarity index 67% rename from mongodb/src/main/scala/io/github/rafafrdz/criteria4s/dialect/mongodb/MongoDB.scala rename to mongodb/src/main/scala/com/eff3ct/criteria4s/dialect/mongodb/MongoDB.scala index 378318c..5b8f873 100644 --- a/mongodb/src/main/scala/io/github/rafafrdz/criteria4s/dialect/mongodb/MongoDB.scala +++ b/mongodb/src/main/scala/com/eff3ct/criteria4s/dialect/mongodb/MongoDB.scala @@ -1,7 +1,31 @@ -package io.github.rafafrdz.criteria4s.dialect.mongodb +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ -import io.github.rafafrdz.criteria4s.core._ -import io.github.rafafrdz.criteria4s.instances._ +package com.eff3ct.criteria4s.dialect.mongodb + +import com.eff3ct.criteria4s.core._ +import com.eff3ct.criteria4s.instances._ trait MongoDB extends CriteriaTag diff --git a/mongodb/src/main/scala/com/eff3ct/criteria4s/dialect/mongodb/package.scala b/mongodb/src/main/scala/com/eff3ct/criteria4s/dialect/mongodb/package.scala new file mode 100644 index 0000000..60e60d2 --- /dev/null +++ b/mongodb/src/main/scala/com/eff3ct/criteria4s/dialect/mongodb/package.scala @@ -0,0 +1,29 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.dialect + +package object mongodb extends MongoDB.MongoDBExpr[MongoDB] { + type MongoDBExpr[T <: MongoDB] = MongoDB.MongoDBExpr[T] +} diff --git a/mongodb/src/main/scala/io/github/rafafrdz/criteria4s/dialect/mongodb/package.scala b/mongodb/src/main/scala/io/github/rafafrdz/criteria4s/dialect/mongodb/package.scala deleted file mode 100644 index ae272b3..0000000 --- a/mongodb/src/main/scala/io/github/rafafrdz/criteria4s/dialect/mongodb/package.scala +++ /dev/null @@ -1,5 +0,0 @@ -package io.github.rafafrdz.criteria4s.dialect - -package object mongodb extends MongoDB.MongoDBExpr[MongoDB] { - type MongoDBExpr[T <: MongoDB] = MongoDB.MongoDBExpr[T] -} diff --git a/project/Build.scala b/project/Build.scala index 68c4864..f0e8b73 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -1,12 +1,14 @@ -import sbt.* -import sbt.Keys.* +import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport.{HeaderLicense, headerLicense} +import de.heikoseeberger.sbtheader.{HeaderPlugin, License} +import sbt.Keys._ +import sbt._ import sbt.plugins.JvmPlugin -import sbtassembly.AssemblyKeys.* +import sbtassembly.AssemblyKeys._ import sbtassembly.{MergeStrategy, PathList} object Build extends AutoPlugin { - override def requires: Plugins = JvmPlugin + override def requires: Plugins = JvmPlugin && HeaderPlugin override def trigger: PluginTrigger = allRequirements @@ -17,25 +19,36 @@ object Build extends AutoPlugin { ) lazy val localJvmSettings: Seq[String] = - Seq("-Xms384M", "-Xmx384M", "-XX:MaxMetaspaceSize=150M", "-XX:+PrintCommandLineFlags") + Seq( + "-Xms384M", + "-Xmx384M", + "-XX:MaxMetaspaceSize=150M", + "-XX:+PrintCommandLineFlags", + "-XX:+CMSClassUnloadingEnabled", + "-Duser.timezone=GMT", + "-XX:+PrintCommandLineFlags", + "-XX:+CMSClassUnloadingEnabled" + ) override def projectSettings: Seq[Setting[_]] = Vector( - ThisBuild / organization := "io.github.rafafrdz", - ThisBuild / name := "criteria-dsl", + ThisBuild / organizationName := "eff3ct", + ThisBuild / organization := "com.eff3ct", ThisBuild / scalaVersion := Version.Scala, ThisBuild / crossScalaVersions := Vector(scalaVersion.value), ThisBuild / javacOptions := Seq("-g:none"), ThisBuild / run / javaOptions ++= localJvmSettings, ThisBuild / run / fork := true, ThisBuild / Test / fork := true, + headerLicense := Some(headerIOLicense), ThisBuild / scalacOptions ++= Vector( - "-target:jvm-1.8", - "-deprecation", // Emit warning and location for usages of deprecated APIs. - "-encoding", - "utf-8", // Specify character encoding used by source files. + "-release:8", + "-deprecation", // Emit warnings for deprecated APIs + "-feature", // Warn about features that should be imported explicitly + "-encoding", "UTF-8", // Specify encoding for source files + "-Xlint" , // Enable recommended additional warnings + "-Ymacro-annotations", "-explaintypes", // Explain type errors in more detail. - "-feature", // Emit warning and location for usages of features that should be imported explicitly. "-language:existentials", // Existential types (besides wildcard types) can be written and inferred "-language:experimental.macros", // Allow macro definition (besides implementation and application) "-language:higherKinds", // Allow higher-kinded types @@ -98,7 +111,7 @@ object Build extends AutoPlugin { // -v Log "test run started" / "test started" / "test run finished" events on log level "info" instead of "debug" // -a Show stack traces and exception class name for AssertionErrors ThisBuild / Test / testOptions += Tests.Argument(TestFrameworks.JUnit, "-v", "-a") - ) + ) ++ SonatypePublish.projectSettings lazy val assemblySettings = Seq( assembly / assemblyMergeStrategy := { @@ -109,4 +122,35 @@ object Build extends AutoPlugin { }, assembly / assemblyJarName := s"${name.value}-${version.value}.jar" ) + + /** + * SBT Header Plugin + */ + + lazy val headerText: String = + """|MIT License + | + |Copyright (c) 2024 Rafael Fernandez + | + |Permission is hereby granted, free of charge, to any person obtaining a copy + |of this software and associated documentation files (the "Software"), to deal + |in the Software without restriction, including without limitation the rights + |to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + |copies of the Software, and to permit persons to whom the Software is + |furnished to do so, subject to the following conditions: + | + |The above copyright notice and this permission notice shall be included in all + |copies or substantial portions of the Software. + | + |THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + |IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + |FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + |AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + |LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + |OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + |SOFTWARE. + |""".stripMargin + + lazy val headerIOLicense: License.Custom = + HeaderLicense.Custom(headerText) } diff --git a/project/NoPublish.scala b/project/NoPublish.scala deleted file mode 100644 index ac24c7a..0000000 --- a/project/NoPublish.scala +++ /dev/null @@ -1,14 +0,0 @@ -import sbt._ -import sbt.Keys._ -import sbt.plugins.JvmPlugin - -object NoPublish extends AutoPlugin { - - override def requires: JvmPlugin.type = plugins.JvmPlugin - - override def projectSettings = Seq( - publishArtifact := false, - publish := {}, - publishLocal := {} - ) -} \ No newline at end of file diff --git a/project/SonatypePublish.scala b/project/SonatypePublish.scala new file mode 100644 index 0000000..8a85eaf --- /dev/null +++ b/project/SonatypePublish.scala @@ -0,0 +1,43 @@ +import sbt.Keys._ +import sbt.{url, _} +import xerial.sbt.Sonatype._ +import xerial.sbt.Sonatype.autoImport._ + +import scala.collection.Seq + +object SonatypePublish { + + def projectSettings: Seq[Setting[_]] = Seq( + ThisBuild / publish / skip := true, + ThisBuild / versionScheme := Some("early-semver"), + ThisBuild / sonatypeCredentialHost := sonatypeCentralHost, + ThisBuild / organization := "com.eff3ct", + ThisBuild / organizationName := "eff3ct", + ThisBuild / organizationHomepage := Some(url("https://github.com/ef3ct")), + ThisBuild / homepage := Some(url("https://github.com/ef3ct/criteria4s")), + ThisBuild / licenses := Seq("MIT" -> url("https://opensource.org/licenses/MIT")), + ThisBuild / description := "A simple DSL to create criterias for filtering data in Scala.", + ThisBuild / scmInfo := Some( + ScmInfo( + browseUrl = url("https://github.com/ef3ct/criteria4s"), + connection = "scm:git@github.com:ef3ct/criteria4s.git" + ) + ), + ThisBuild / developers := List( + Developer( + id = "rafafrdz", + name = "Rafael Fernandez", + email = "hi@rafaelfernandez.dev", + url = url("https://rafaelfernandez.dev") + ) + ), + ThisBuild / sonatypeProjectHosting := Some( + GitHubHosting( + user = "ef3ct", + repository = "criteria4s", + email = "hi@rafaelfernandez.dev" + ) + ) + ) + +} diff --git a/project/plugins.sbt b/project/plugins.sbt index 768d9c1..0bffe24 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,4 +1,7 @@ -addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.15") -addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0") -addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0") +/** Build */ +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.3.0") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2") +addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.10.0") + +/** Publish */ +addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.9.2") \ No newline at end of file diff --git a/publish.sbt b/publish.sbt deleted file mode 100644 index 9735475..0000000 --- a/publish.sbt +++ /dev/null @@ -1,40 +0,0 @@ -import xerial.sbt.Sonatype.* - -ThisBuild / organization := "io.github.rafafrdz" -ThisBuild / organizationName := "rafafrdz" -ThisBuild / sonatypeProfileName := "io.github.rafafrdz" -ThisBuild / organizationHomepage := Some(url("https://github.com/rafafrdz")) -ThisBuild / homepage := Some(url("https://github.com/rafafrdz/criteria4s")) - -ThisBuild / scmInfo := Some( - ScmInfo( - url("https://github.com/rafafrdz/criteria4s"), - "scm:git@github.com:rafafrdz/criteria4s.git" - ) -) - -ThisBuild / developers := List( - Developer( - id = "rafafrdz", - name = "Rafael Fernández Ortiz", - email = "criteria4s@rafaelfernandez.dev", - url = url("https://github.com/rafafrdz") - ) -) -ThisBuild / description := "A simple DSL to create criterias for filtering data in Scala." -ThisBuild / licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")) -ThisBuild / publish / skip := true -ThisBuild / versionScheme := Some("early-semver") -ThisBuild / pomIncludeRepository := { _ => false } - -/** Reference the project OSS repository */ -// Repository for releases on Maven Central using Sonatype -ThisBuild / sonatypeCredentialHost := "s01.oss.sonatype.org" -ThisBuild / sonatypeRepository := "https://s01.oss.sonatype.org/service/local" -ThisBuild / sonatypeProjectHosting := Some( - GitHubHosting( - user = "rafafrdz", - repository = "criteria4s", - email = "criteria4s@rafaelfernandez.dev" - ) -) diff --git a/sql/src/main/scala/io/github/rafafrdz/criteria4s/dialect/sql/SQL.scala b/sql/src/main/scala/com/eff3ct/criteria4s/dialect/sql/SQL.scala similarity index 65% rename from sql/src/main/scala/io/github/rafafrdz/criteria4s/dialect/sql/SQL.scala rename to sql/src/main/scala/com/eff3ct/criteria4s/dialect/sql/SQL.scala index 3a55e2c..2a71b45 100644 --- a/sql/src/main/scala/io/github/rafafrdz/criteria4s/dialect/sql/SQL.scala +++ b/sql/src/main/scala/com/eff3ct/criteria4s/dialect/sql/SQL.scala @@ -1,7 +1,31 @@ -package io.github.rafafrdz.criteria4s.dialect.sql +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ -import io.github.rafafrdz.criteria4s.core._ -import io.github.rafafrdz.criteria4s.instances._ +package com.eff3ct.criteria4s.dialect.sql + +import com.eff3ct.criteria4s.core._ +import com.eff3ct.criteria4s.instances._ trait SQL extends CriteriaTag diff --git a/sql/src/main/scala/com/eff3ct/criteria4s/dialect/sql/package.scala b/sql/src/main/scala/com/eff3ct/criteria4s/dialect/sql/package.scala new file mode 100644 index 0000000..810de05 --- /dev/null +++ b/sql/src/main/scala/com/eff3ct/criteria4s/dialect/sql/package.scala @@ -0,0 +1,30 @@ +/* + * MIT License + * + * Copyright (c) 2024 Rafael Fernandez + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package com.eff3ct.criteria4s.dialect + +package object sql extends SQL.SQLExpr[SQL] { + + type SQLExpr[T <: SQL] = SQL.SQLExpr[T] +} diff --git a/sql/src/main/scala/io/github/rafafrdz/criteria4s/dialect/sql/package.scala b/sql/src/main/scala/io/github/rafafrdz/criteria4s/dialect/sql/package.scala deleted file mode 100644 index ca192e6..0000000 --- a/sql/src/main/scala/io/github/rafafrdz/criteria4s/dialect/sql/package.scala +++ /dev/null @@ -1,6 +0,0 @@ -package io.github.rafafrdz.criteria4s.dialect - -package object sql extends SQL.SQLExpr[SQL] { - - type SQLExpr[T <: SQL] = SQL.SQLExpr[T] -}