From c04968803addc9f6b6305f4d4e88f67b7c2ba11d Mon Sep 17 00:00:00 2001 From: tx7do Date: Fri, 24 Nov 2023 13:10:52 +0800 Subject: [PATCH] fix: #1 document error. --- .gitignore | 26 ++++++++++++++++++------ entgo/query/README.md | 46 +++++++++++++++++++++---------------------- 2 files changed, 43 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 3b735ec..d981b6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ -# If you prefer the allow list template instead of the deny list, see community template: -# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore -# +# Reference https://github.com/github/gitignore/blob/master/Go.gitignore # Binaries for programs and plugins *.exe *.exe~ @@ -15,7 +13,23 @@ *.out # Dependency directories (remove the comment below to include it) -# vendor/ +vendor/ -# Go workspace file -go.work +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a + +# OS General +Thumbs.db +.DS_Store + +# project +*.cert +*.key +*.log +bin/ + +# Develop tools +.vscode/ +.idea/ +*.swp diff --git a/entgo/query/README.md b/entgo/query/README.md index 8b92b05..8c0b5f3 100644 --- a/entgo/query/README.md +++ b/entgo/query/README.md @@ -38,29 +38,29 @@ {字段名}__{查找类型} : {值} ``` -| 查找类型 | 示例 | SQL | 备注 | -|-------------|---------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------| -| not | `{"name__not" : "tom"}` | `WHERE NOT ("name" = "tom")` | | -| in | `{"name__in" : ["tom", "jimmy"]}` | `WHERE name IN ("tom", "jimmy")` | | -| not_in | `{"name__not_in" : ["tom", "jimmy"]}` | `WHERE name NOT IN ("tom", "jimmy")` | | -| gte | `{"create_time__gte" : "2023-10-25"}` | `WHERE "create_time" >= "2023-10-25"` | | -| gt | `{"create_time__gt" : "2023-10-25"}` | `WHERE "create_time" > "2023-10-25"` | | -| lte | `{"create_time__lte" : "2023-10-25"}` | `WHERE "create_time" <= "2023-10-25"` | | -| lt | `{"create_time__lt" : "2023-10-25"}` | `WHERE "create_time" < "2023-10-25"` | | -| range | `{"create_time__range" : ["2023-10-25", "2024-10-25"]}` | `WHERE "create_time" BETWEEN "2023-10-25" AND "2024-10-25"`

`WHERE "create_time" >= "2023-10-25" AND "create_time" <= "2024-10-25"` | 需要注意的是:
1. 有些数据库的BETWEEN实现的开闭区间可能不一样。
2. 日期`2005-01-01`会被隐式转换为:`2005-01-01 00:00:00`,两个日期一致就会导致查询不到数据。 | -| isnull | `{"name__isnull" : "True"}` | `WHERE name IS NULL` | | -| not_isnull | `{"name__not_isnull" : "False"}` | `WHERE name IS NOT NULL` | | -| contains | `{"name__contains" : "L"}` | `WHERE name LIKE '%L%';` | | -| icontains | `{"name__icontains" : "L"}` | `WHERE name ILIKE '%L%';` | | -| startswith | `{"name__startswith" : "La"}` | `WHERE name LIKE 'La%';` | | -| istartswith | `{"name__istartswith" : "La"}` | `WHERE name ILIKE 'La%';` | | -| endswith | `{"name__endswith" : "a"}` | `WHERE name LIKE '%a';` | | -| iendswith | `{"name__iendswith" : "a"}` | `WHERE name ILIKE '%a';` | | -| exact | `{"name__exact" : "a"}` | `WHERE name LIKE 'a';` | | -| iexact | `{"name__iexact" : "a"}` | `WHERE name ILIKE 'a';` | | -| regex | `{"title__regex" : "^(An?\|The) +"}` | MySQL: `WHERE title REGEXP BINARY '^(An?\|The) +'`
Oracle: `WHERE REGEXP_LIKE(title, '^(An?\|The) +', 'c');`
PostgreSQL: `WHERE title ~ '^(An?\|The) +';`
SQLite: `WHERE title REGEXP '^(An?\|The) +';` | | -| iregex | `{"title__iregex" : "^(an?\|the) +"}` | MySQL: `WHERE title REGEXP '^(an?\|the) +'`
Oracle: `WHERE REGEXP_LIKE(title, '^(an?\|the) +', 'i');`
PostgreSQL: `WHERE title ~* '^(an?\|the) +';`
SQLite: `WHERE title REGEXP '(?i)^(an?\|the) +';` | | -| search | | | | +| 查找类型 | 示例 | SQL | 备注 | +|-------------|---------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------| +| not | `{"name__not" : "tom"}` | `WHERE NOT ("name" = "tom")` | | +| in | `{"name__in" : "[\"tom\", \"jimmy\"]"}` | `WHERE name IN ("tom", "jimmy")` | | +| not_in | `{"name__not_in" : "[\"tom\", \"jimmy\"]"}` | `WHERE name NOT IN ("tom", "jimmy")` | | +| gte | `{"create_time__gte" : "2023-10-25"}` | `WHERE "create_time" >= "2023-10-25"` | | +| gt | `{"create_time__gt" : "2023-10-25"}` | `WHERE "create_time" > "2023-10-25"` | | +| lte | `{"create_time__lte" : "2023-10-25"}` | `WHERE "create_time" <= "2023-10-25"` | | +| lt | `{"create_time__lt" : "2023-10-25"}` | `WHERE "create_time" < "2023-10-25"` | | +| range | `{"create_time__range" : "[\"2023-10-25\", \"2024-10-25\"]"}` | `WHERE "create_time" BETWEEN "2023-10-25" AND "2024-10-25"`

`WHERE "create_time" >= "2023-10-25" AND "create_time" <= "2024-10-25"` | 需要注意的是:
1. 有些数据库的BETWEEN实现的开闭区间可能不一样。
2. 日期`2005-01-01`会被隐式转换为:`2005-01-01 00:00:00`,两个日期一致就会导致查询不到数据。 | +| isnull | `{"name__isnull" : "True"}` | `WHERE name IS NULL` | | +| not_isnull | `{"name__not_isnull" : "False"}` | `WHERE name IS NOT NULL` | | +| contains | `{"name__contains" : "L"}` | `WHERE name LIKE '%L%';` | | +| icontains | `{"name__icontains" : "L"}` | `WHERE name ILIKE '%L%';` | | +| startswith | `{"name__startswith" : "La"}` | `WHERE name LIKE 'La%';` | | +| istartswith | `{"name__istartswith" : "La"}` | `WHERE name ILIKE 'La%';` | | +| endswith | `{"name__endswith" : "a"}` | `WHERE name LIKE '%a';` | | +| iendswith | `{"name__iendswith" : "a"}` | `WHERE name ILIKE '%a';` | | +| exact | `{"name__exact" : "a"}` | `WHERE name LIKE 'a';` | | +| iexact | `{"name__iexact" : "a"}` | `WHERE name ILIKE 'a';` | | +| regex | `{"title__regex" : "^(An?\|The) +"}` | MySQL: `WHERE title REGEXP BINARY '^(An?\|The) +'`
Oracle: `WHERE REGEXP_LIKE(title, '^(An?\|The) +', 'c');`
PostgreSQL: `WHERE title ~ '^(An?\|The) +';`
SQLite: `WHERE title REGEXP '^(An?\|The) +';` | | +| iregex | `{"title__iregex" : "^(an?\|the) +"}` | MySQL: `WHERE title REGEXP '^(an?\|the) +'`
Oracle: `WHERE REGEXP_LIKE(title, '^(an?\|the) +', 'i');`
PostgreSQL: `WHERE title ~* '^(an?\|the) +';`
SQLite: `WHERE title REGEXP '(?i)^(an?\|the) +';` | | +| search | | | | 以及将日期提取出来的查找类型: