mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-16 07:57:33 +08:00
Add PgsqlArrayContains
This commit is contained in:
parent
eec8936a8b
commit
02b1f1f9db
@ -1192,5 +1192,35 @@ namespace SqlSugar
|
||||
var searchWord = mode.Args[1].MemberName;
|
||||
return $"to_tsvector('chinese', {columns}) @@ to_tsquery('chinese', {searchWord})";
|
||||
}
|
||||
|
||||
public virtual string PgsqlArrayContains(MethodCallExpressionModel model)
|
||||
{
|
||||
// 如果model.Args[1]是一个复杂类型,你可能需要将其转换为字符串或适当的格式
|
||||
// 在这里,我们假设它是一个可以直接转换为字符串的值
|
||||
string valueToFind = model.Args[1].MemberValue.ToString(); // 或者使用适当的转换方法
|
||||
var type = "text";
|
||||
if (model.Args[1].MemberValue is int)
|
||||
{
|
||||
type = "int4";
|
||||
}
|
||||
else if (model.Args[1].MemberValue is long)
|
||||
{
|
||||
type = "int8";
|
||||
}
|
||||
else if (model.Args[1].MemberValue is short)
|
||||
{
|
||||
type = "int2";
|
||||
}
|
||||
if (!UtilMethods.IsNumber(model.Args[1].MemberValue.GetType().Name))
|
||||
{
|
||||
valueToFind = $"'{valueToFind}'";
|
||||
}
|
||||
// PostgreSQL查询字符串
|
||||
string queryCondition = $"{model.Args[0].MemberName}::{type}[] @> ARRAY[{valueToFind}]";
|
||||
|
||||
// 如果需要处理NULL值或其他复杂情况,请在这里添加逻辑
|
||||
|
||||
return queryCondition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -127,5 +127,6 @@ namespace SqlSugar
|
||||
string Ceil(MethodCallExpressionModel mode);
|
||||
string NewUid(MethodCallExpressionModel mode);
|
||||
string FullTextContains(MethodCallExpressionModel mode);
|
||||
string PgsqlArrayContains(MethodCallExpressionModel model);
|
||||
}
|
||||
}
|
||||
|
@ -396,10 +396,13 @@ namespace SqlSugar
|
||||
public static int SqlServer_DateDiff(string dateType,DateTime date1,DateTime date2) { throw new NotSupportedException("Can only be used in expressions"); }
|
||||
|
||||
public static bool JsonListObjectAny(object jsonListObject, string fieldName, object value)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
public static bool PgsqlArrayContains(object jsonArray, object arrayValue)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
|
||||
public static bool JsonArrayAny(object jsonArray,object arrayValue)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
|
Loading…
Reference in New Issue
Block a user