From bd1dfdca65c517ec4f0ac51a4580aec53e841bf3 Mon Sep 17 00:00:00 2001
From: wangyu <727842003@qq.com>
Date: Tue, 6 Sep 2022 16:13:01 +0800
Subject: [PATCH] feat: init the project
---
.gitignore | 5 +
LICENSE | 201 ++++++++++
README.md | 107 ++++++
fluent-sql-core/pom.xml | 37 ++
.../group/flyfish/fluent/binding/Alias.java | 19 +
.../flyfish/fluent/binding/JSONInject.java | 14 +
.../group/flyfish/fluent/chain/Order.java | 26 ++
.../group/flyfish/fluent/chain/OrderImpl.java | 37 ++
.../java/group/flyfish/fluent/chain/SQL.java | 64 ++++
.../flyfish/fluent/chain/SQLFactory.java | 19 +
.../group/flyfish/fluent/chain/SQLImpl.java | 255 ++++++++++++
.../flyfish/fluent/chain/SQLOperations.java | 30 ++
.../flyfish/fluent/chain/SQLSegment.java | 29 ++
.../chain/common/AfterJoinSqlChain.java | 26 ++
.../fluent/chain/common/ExecutableSql.java | 16 +
.../fluent/chain/common/HandleSqlChain.java | 20 +
.../fluent/chain/common/JoinOperations.java | 84 ++++
.../fluent/chain/common/PreSqlChain.java | 26 ++
.../chain/select/AfterOrderSqlChain.java | 32 ++
.../chain/select/AfterWhereSqlChain.java | 19 +
.../fluent/chain/select/SelectComposite.java | 73 ++++
.../fluent/chain/update/AfterSetSqlChain.java | 22 ++
.../fluent/mapping/SQLMappedRowMapper.java | 362 ++++++++++++++++++
.../flyfish/fluent/query/ConcatCandidate.java | 27 ++
.../group/flyfish/fluent/query/Condition.java | 47 +++
.../fluent/query/ConditionCandidate.java | 72 ++++
.../flyfish/fluent/query/JoinCandidate.java | 26 ++
.../flyfish/fluent/query/Parameterized.java | 32 ++
.../group/flyfish/fluent/query/Query.java | 72 ++++
.../flyfish/fluent/query/SimpleCondition.java | 115 ++++++
.../flyfish/fluent/query/SimpleQuery.java | 142 +++++++
.../group/flyfish/fluent/update/Update.java | 52 +++
.../flyfish/fluent/update/UpdateImpl.java | 110 ++++++
.../flyfish/fluent/utils/cache/LRUCache.java | 36 ++
.../fluent/utils/context/AliasComposite.java | 182 +++++++++
.../fluent/utils/data/ObjectMappers.java | 32 ++
.../fluent/utils/data/ParameterUtils.java | 31 ++
.../fluent/utils/sql/ConcatSegment.java | 63 +++
.../fluent/utils/sql/EntityNameUtils.java | 157 ++++++++
.../flyfish/fluent/utils/sql/SFunction.java | 82 ++++
.../fluent/utils/sql/SerializedLambda.java | 156 ++++++++
.../fluent/utils/sql/SqlNameUtils.java | 103 +++++
.../fluent/utils/text/TemplateCompiler.java | 98 +++++
fluent-sql-jdbctemplate/pom.xml | 19 +
pom.xml | 181 +++++++++
45 files changed, 3358 insertions(+)
create mode 100644 .gitignore
create mode 100644 LICENSE
create mode 100644 README.md
create mode 100644 fluent-sql-core/pom.xml
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/binding/Alias.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/binding/JSONInject.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/chain/Order.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/chain/OrderImpl.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/chain/SQL.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/chain/SQLFactory.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/chain/SQLImpl.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/chain/SQLOperations.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/chain/SQLSegment.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/chain/common/AfterJoinSqlChain.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/chain/common/ExecutableSql.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/chain/common/HandleSqlChain.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/chain/common/JoinOperations.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/chain/common/PreSqlChain.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/chain/select/AfterOrderSqlChain.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/chain/select/AfterWhereSqlChain.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/chain/select/SelectComposite.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/chain/update/AfterSetSqlChain.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/mapping/SQLMappedRowMapper.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/query/ConcatCandidate.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/query/Condition.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/query/ConditionCandidate.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/query/JoinCandidate.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/query/Parameterized.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/query/Query.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/query/SimpleCondition.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/query/SimpleQuery.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/update/Update.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/update/UpdateImpl.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/utils/cache/LRUCache.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/utils/context/AliasComposite.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/utils/data/ObjectMappers.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/utils/data/ParameterUtils.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/utils/sql/ConcatSegment.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/utils/sql/EntityNameUtils.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/utils/sql/SFunction.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/utils/sql/SerializedLambda.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/utils/sql/SqlNameUtils.java
create mode 100644 fluent-sql-core/src/main/java/group/flyfish/fluent/utils/text/TemplateCompiler.java
create mode 100644 fluent-sql-jdbctemplate/pom.xml
create mode 100644 pom.xml
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..60245d2
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+.idea
+*.iml
+.DS_Store
+
+target
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,201 @@
+ 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.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..f98d5fd
--- /dev/null
+++ b/README.md
@@ -0,0 +1,107 @@
+# fluent-sql
+
+基于Fluent Api实现的SQL构建器,秒杀mybatis plus的存在,易用性的API让你爽到飞起。
+
+## 特性介绍
+
+1. 实现了SQL底层的语法解析,创新使用片段的构建模式,忽略嵌套层级任意嵌套
+2. 高质量的代码,没有一点点冗余的设计,为您的代码保驾护航
+3. 天生自带防SQL注入和条件空策略解析,后续会增加更加精细的配置
+4. 支持任意多表的关联查询和数据绑定
+5. 支持返回实体映射,基于注解式开发,更解耦,更面向对象
+6. 智能别名策略,写查询再也不用担心多张表的别名问题,代码简介易懂,用java跟sql体验直接拉满
+7. 高精度api控制,sql构建每个步骤严格把关,保证输入一个api立即能写出来接下来的步骤还不出错
+
+## 快速使用
+
+本小组件主要解决的是sql的书写问题,旨在用更加优雅的方式实现sql,并且不用再担心数据库方言(SQL Dialect)
+变化导致的频繁变更SQL问题。
+
+如果要实现下面一段SQL
+
+```sql
+SELECT t1.`id` AS `id`,
+ t1.`name` AS `name`,
+ t1.`identifier` AS `identifier`,
+ `max_tenant` AS `maxTenant`,
+ t2.`related_id` AS `relatedId`
+FROM saas_tenant `t1`
+ INNER JOIN saas_quota `t2` ON t2.`related_id` = t1.`id`
+ AND t1.`identifier` = ?
+WHERE t1.`id` = ?
+ AND t1.`name` LIKE CONCAT(%,?,%)
+ AND t2.`related_id` IN (?, ?)
+ AND t2.`related_type` = ?
+ORDER BY t1.`create_time` DESC,
+ t1.`id` ASC
+```
+
+您只需要写以下java代码:
+
+```java
+public class TestSql {
+
+ /**
+ * 执行sql测试
+ * @return 最终组装的实体
+ */
+ public TenantContext executeSql() {
+ // 查询开始
+ return select(
+ // 某张表的几个字段
+ composite(SaasTenant::getId, SaasTenant::getName, SaasTenant::getIdentifier),
+ // 某张表的全量字段
+ all(SaasProperties.class),
+ // 其他表的字段
+ composite(SaasQuota::getId, SaasQuota::getRelatedType),
+ // 指定别名的字段
+ composite(SaasQuota::getRelatedId, "relatedOtherId"))
+ .from(SaasTenant.class)
+ .join(SaasQuota.class).on(where(SaasQuota::getRelatedId).eq(SaasTenant::getId)
+ .and(SaasTenant::getIdentifier).eq(5))
+ .join(SaasProperties.class)
+ .then()
+ .matching(where(SaasTenant::getId).eq("1")
+ .and(SaasTenant::getName).like("王大锤")
+ .and(SaasQuota::getRelatedId).in(Arrays.asList("5", "10"))
+ .and(SaasQuota::getRelatedType).eq(SaasQuota.RelatedType.TENANT)
+ )
+ .order(by(SaasTenant::getCreateTime).desc(), by(SaasTenant::getId).asc())
+ .one(TenantContext.class);
+ }
+}
+```
+
+## 常规步骤
+
+建议使用静态导入,美观代码,如下:
+
+1. SQL.select => select
+2. SelectComposite.composite => composite
+3. SelectComposite.all => all
+4. Order.by => by
+5. Query.where => where
+
+为了方便演示,我们下面的代码都基于静态导入函数:
+
+1. 绑定您执行sql的数据源。如下:
+
+```java
+class SQLConfig {
+
+ void doConfig() {
+ // 创建或者获取您的数据源
+ DataSource = createDataSource(...)
+ // 基于spring jdbc template实例化
+ SQL.bind(new JdbcTemplate(dataSource));
+ }
+}
+
+```
+
+2. 写一个结果对象Vo用来接取执行结果,如快速开始中的`TenantContext`
+3. 用java写sql,然后执行`.one()`或者`.list()`返回一条或者多条。
+4. 查询单表所有字段,请使用`select().from(TableClass.class)`
+5. 查询多表中某个单表的所有字段,请使用`select(all(TableClass.class)).from(TableClass.class).join(Other.class).then()`
+6.
+多张表中查询某些字段,并使用别名,请参考`select(composite(TableA::getName, "nameA"), composite(TableB::getName, "nameB")).from(TableA.class).join(TableB.class)...`
diff --git a/fluent-sql-core/pom.xml b/fluent-sql-core/pom.xml
new file mode 100644
index 0000000..5e2d442
--- /dev/null
+++ b/fluent-sql-core/pom.xml
@@ -0,0 +1,37 @@
+
+
+
+ fluent-sql
+ group.flyfish.framework
+ 1.0-SNAPSHOT
+
+ 4.0.0
+
+ fluent-sql-core
+
+
+ 8
+ 8
+
+
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+
+
+ org.springframework
+ spring-jdbc
+
+
+ javax.persistence
+ persistence-api
+
+
+ org.slf4j
+ slf4j-api
+
+
+
diff --git a/fluent-sql-core/src/main/java/group/flyfish/fluent/binding/Alias.java b/fluent-sql-core/src/main/java/group/flyfish/fluent/binding/Alias.java
new file mode 100644
index 0000000..23c1c18
--- /dev/null
+++ b/fluent-sql-core/src/main/java/group/flyfish/fluent/binding/Alias.java
@@ -0,0 +1,19 @@
+package group.flyfish.fluent.binding;
+
+import java.lang.annotation.*;
+
+/**
+ * 结果映射指定别名
+ *
+ * @author wangyu
+ */
+@Target(ElementType.FIELD)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface Alias {
+
+ /**
+ * @return 别名
+ */
+ String value();
+}
diff --git a/fluent-sql-core/src/main/java/group/flyfish/fluent/binding/JSONInject.java b/fluent-sql-core/src/main/java/group/flyfish/fluent/binding/JSONInject.java
new file mode 100644
index 0000000..d642c3d
--- /dev/null
+++ b/fluent-sql-core/src/main/java/group/flyfish/fluent/binding/JSONInject.java
@@ -0,0 +1,14 @@
+package group.flyfish.fluent.binding;
+
+import java.lang.annotation.*;
+
+/**
+ * json注入
+ *
+ * @author wangyu
+ */
+@Target(ElementType.FIELD)
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface JSONInject {
+}
diff --git a/fluent-sql-core/src/main/java/group/flyfish/fluent/chain/Order.java b/fluent-sql-core/src/main/java/group/flyfish/fluent/chain/Order.java
new file mode 100644
index 0000000..a7e1aac
--- /dev/null
+++ b/fluent-sql-core/src/main/java/group/flyfish/fluent/chain/Order.java
@@ -0,0 +1,26 @@
+package group.flyfish.fluent.chain;
+
+import group.flyfish.fluent.utils.sql.SFunction;
+
+/**
+ * 排序链式声明
+ *
+ * @author wangyu
+ */
+public interface Order extends SQLSegment {
+
+ /**
+ * 以字段排序
+ *
+ * @param field 字段
+ * @param 泛型
+ * @return 链式调用
+ */
+ static Order by(SFunction field) {
+ return new OrderImpl(field);
+ }
+
+ Order asc();
+
+ Order desc();
+}
diff --git a/fluent-sql-core/src/main/java/group/flyfish/fluent/chain/OrderImpl.java b/fluent-sql-core/src/main/java/group/flyfish/fluent/chain/OrderImpl.java
new file mode 100644
index 0000000..3da7f32
--- /dev/null
+++ b/fluent-sql-core/src/main/java/group/flyfish/fluent/chain/OrderImpl.java
@@ -0,0 +1,37 @@
+package group.flyfish.fluent.chain;
+
+import group.flyfish.fluent.utils.sql.SFunction;
+import lombok.RequiredArgsConstructor;
+
+/**
+ * 排序支持
+ *
+ * @author wangyu
+ */
+@RequiredArgsConstructor
+final class OrderImpl implements Order, SQLSegment {
+
+ private final SFunction, ?> field;
+
+ private String order = "asc";
+
+ @Override
+ public OrderImpl asc() {
+ order = "asc";
+ return this;
+ }
+
+ @Override
+ public OrderImpl desc() {
+ order = "desc";
+ return this;
+ }
+
+ /**
+ * @return 得到sql片段
+ */
+ @Override
+ public String get() {
+ return String.join(" ", field.getName(), order);
+ }
+}
diff --git a/fluent-sql-core/src/main/java/group/flyfish/fluent/chain/SQL.java b/fluent-sql-core/src/main/java/group/flyfish/fluent/chain/SQL.java
new file mode 100644
index 0000000..f9afea0
--- /dev/null
+++ b/fluent-sql-core/src/main/java/group/flyfish/fluent/chain/SQL.java
@@ -0,0 +1,64 @@
+package group.flyfish.fluent.chain;
+
+import group.flyfish.fluent.chain.common.PreSqlChain;
+import group.flyfish.fluent.chain.select.SelectComposite;
+import group.flyfish.fluent.update.Update;
+import group.flyfish.fluent.utils.sql.SFunction;
+import org.springframework.jdbc.core.JdbcOperations;
+
+import static group.flyfish.fluent.utils.sql.SqlNameUtils.cast;
+
+/**
+ * 链式查询入口
+ *
+ * @author wangyu
+ */
+public interface SQL {
+
+ /**
+ * 查询起手式
+ *
+ * @return 自身
+ */
+ @SafeVarargs
+ static PreSqlChain select(SFunction... fields) {
+ return SQLFactory.produce().select(fields);
+ }
+
+ /**
+ * 查询起手式
+ *
+ * @return 自身
+ */
+ static PreSqlChain select(SelectComposite>... composites) {
+ return SQLFactory.produce().select(SelectComposite.combine(composites));
+ }
+
+ /**
+ * 查询起手式,查询全部字段
+ *
+ * @return 结果
+ */
+ static PreSqlChain select() {
+ return SQLFactory.produce().select(cast(new SFunction[]{}));
+ }
+
+ /**
+ * 更新表起手
+ *
+ * @param clazz 表
+ * @return 更新链式
+ */
+ static Update update(Class> clazz) {
+ return SQLFactory.produce().update(clazz);
+ }
+
+ /**
+ * 绑定数据源上下文,基于jdbc template
+ *
+ * @param operations jdbc操作
+ */
+ static void bind(JdbcOperations operations) {
+ SQLImpl.bind(operations);
+ }
+}
diff --git a/fluent-sql-core/src/main/java/group/flyfish/fluent/chain/SQLFactory.java b/fluent-sql-core/src/main/java/group/flyfish/fluent/chain/SQLFactory.java
new file mode 100644
index 0000000..4a7c2b3
--- /dev/null
+++ b/fluent-sql-core/src/main/java/group/flyfish/fluent/chain/SQLFactory.java
@@ -0,0 +1,19 @@
+package group.flyfish.fluent.chain;
+
+/**
+ * sql工厂
+ *
+ * @author wangyu
+ * 普通静态工厂,用于生产实现实例
+ */
+public interface SQLFactory {
+
+ /**
+ * 生产实例
+ *
+ * @return sql操作
+ */
+ static SQLOperations produce() {
+ return new SQLImpl();
+ }
+}
diff --git a/fluent-sql-core/src/main/java/group/flyfish/fluent/chain/SQLImpl.java b/fluent-sql-core/src/main/java/group/flyfish/fluent/chain/SQLImpl.java
new file mode 100644
index 0000000..bb3ad7e
--- /dev/null
+++ b/fluent-sql-core/src/main/java/group/flyfish/fluent/chain/SQLImpl.java
@@ -0,0 +1,255 @@
+package group.flyfish.fluent.chain;
+
+import group.flyfish.fluent.chain.common.AfterJoinSqlChain;
+import group.flyfish.fluent.chain.common.HandleSqlChain;
+import group.flyfish.fluent.chain.common.PreSqlChain;
+import group.flyfish.fluent.chain.select.AfterOrderSqlChain;
+import group.flyfish.fluent.chain.select.AfterWhereSqlChain;
+import group.flyfish.fluent.chain.update.AfterSetSqlChain;
+import group.flyfish.fluent.mapping.SQLMappedRowMapper;
+import group.flyfish.fluent.query.JoinCandidate;
+import group.flyfish.fluent.query.Parameterized;
+import group.flyfish.fluent.query.Query;
+import group.flyfish.fluent.update.Update;
+import group.flyfish.fluent.update.UpdateImpl;
+import group.flyfish.fluent.utils.context.AliasComposite;
+import group.flyfish.fluent.utils.data.ParameterUtils;
+import group.flyfish.fluent.utils.sql.ConcatSegment;
+import group.flyfish.fluent.utils.sql.EntityNameUtils;
+import group.flyfish.fluent.utils.sql.SFunction;
+import group.flyfish.fluent.utils.sql.SqlNameUtils;
+import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.jdbc.core.JdbcOperations;
+import org.springframework.util.Assert;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * 查询工具类
+ *
+ * @author wangyu
+ */
+final class SQLImpl extends ConcatSegment implements SQLOperations, PreSqlChain, HandleSqlChain, AfterJoinSqlChain, AfterSetSqlChain {
+
+ // 共享的操作
+ private static JdbcOperations SHARED_OPERATIONS;
+ // 参数map,有序
+ private final List