001/** 002 * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.mybatisflex.core.query; 017 018public class QueryMethods { 019 020 public static FunctionQueryColumn count() { 021 return new FunctionQueryColumn("COUNT", new StringQueryColumn("*")); 022 } 023 024 public static FunctionQueryColumn count(String column) { 025 return new FunctionQueryColumn("COUNT", column); 026 } 027 028 public static FunctionQueryColumn count(QueryColumn column) { 029 return new FunctionQueryColumn("COUNT", column); 030 } 031 032 public static FunctionQueryColumn max(String column) { 033 return new FunctionQueryColumn("MAX", column); 034 } 035 036 public static FunctionQueryColumn max(QueryColumn column) { 037 return new FunctionQueryColumn("MAX", column); 038 } 039 040 public static FunctionQueryColumn min(String column) { 041 return new FunctionQueryColumn("MIN", column); 042 } 043 044 public static FunctionQueryColumn min(QueryColumn column) { 045 return new FunctionQueryColumn("MIN", column); 046 } 047 048 public static FunctionQueryColumn avg(String column) { 049 return new FunctionQueryColumn("AVG", column); 050 } 051 052 public static FunctionQueryColumn avg(QueryColumn column) { 053 return new FunctionQueryColumn("AVG", column); 054 } 055 056 public static FunctionQueryColumn sum(String column) { 057 return new FunctionQueryColumn("SUM", column); 058 } 059 060 public static FunctionQueryColumn sum(QueryColumn column) { 061 return new FunctionQueryColumn("SUM", column); 062 } 063 064 public static DistinctQueryColumn distinct(QueryColumn... columns) { 065 return new DistinctQueryColumn(columns); 066 } 067 068 069 public static StringQueryColumn column(String column) { 070 return new StringQueryColumn(column); 071 } 072 073 public static QueryCondition exist(QueryWrapper queryWrapper) { 074 return new OperatorSelectCondition(" EXIST ", queryWrapper); 075 } 076 077 public static QueryCondition notExist(QueryWrapper queryWrapper) { 078 return new OperatorSelectCondition(" NOT EXIST ", queryWrapper); 079 } 080 081 public static QueryCondition not(QueryCondition childCondition) { 082 return new OperatorQueryCondition(" NOT ", childCondition); 083 } 084 085 public static QueryCondition noCondition(){ 086 return QueryCondition.createEmpty(); 087 } 088 089 private static QueryWrapper newWrapper() { 090 return new QueryWrapper(); 091 } 092 093 094 public static QueryWrapper select(QueryColumn... queryColumns) { 095 return newWrapper().select(queryColumns); 096 } 097 098 099 public static QueryWrapper selectOne() { 100 return select(column("1")); 101 } 102 103 public static RawValue raw(String raw){ 104 return new RawValue(raw); 105 } 106 107}