-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support translate for prisma error.
- Loading branch information
xufeixiang
committed
May 31, 2024
1 parent
e35832e
commit c352c92
Showing
6 changed files
with
354 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Package i18n | ||
/* | ||
查询引擎错误国际化配置,使用i18n-stringer实现 | ||
*/ | ||
package i18n | ||
|
||
import ( | ||
"github.com/spf13/cast" | ||
"github.com/wundergraph/wundergraph/pkg/datasources/database" | ||
) | ||
|
||
// First check | ||
//go:generate $GOPATH/bin/i18n-stringer -type PrismaError -tomlpath prisma_error -check | ||
|
||
// Second generation | ||
//go:generate $GOPATH/bin/i18n-stringer -type PrismaError -tomlpath prisma_error -defaultlocale zh_cn | ||
|
||
func init() { | ||
database.TranslateErrorFunc = func(code string) string { | ||
return PrismaError._transOne(PrismaError(cast.ToInt(code[1:])), _PrismaError_defaultLocale) | ||
} | ||
} | ||
|
||
func SwitchPrismaErrorLocale(locale string) bool { | ||
result := _PrismaError_isLocaleSupport(locale) | ||
if result { | ||
_PrismaError_defaultLocale = locale | ||
} | ||
return result | ||
} | ||
|
||
type PrismaError uint16 | ||
|
||
// PrismaQueryError | ||
const ( | ||
PrismaError_P2000 PrismaError = 2000 + iota | ||
PrismaError_P2001 | ||
PrismaError_P2002 | ||
PrismaError_P2003 | ||
PrismaError_P2004 | ||
PrismaError_P2005 | ||
PrismaError_P2006 | ||
PrismaError_P2007 | ||
PrismaError_P2008 | ||
PrismaError_P2009 | ||
PrismaError_P2010 | ||
PrismaError_P2011 | ||
PrismaError_P2012 | ||
PrismaError_P2013 | ||
PrismaError_P2014 | ||
PrismaError_P2015 | ||
PrismaError_P2016 | ||
PrismaError_P2017 | ||
PrismaError_P2018 | ||
PrismaError_P2019 | ||
PrismaError_P2020 | ||
PrismaError_P2021 | ||
PrismaError_P2022 | ||
PrismaError_P2023 | ||
PrismaError_P2024 | ||
PrismaError_P2025 | ||
PrismaError_P2026 | ||
PrismaError_P2027 | ||
PrismaError_P2028 | ||
PrismaError_P2029 | ||
PrismaError_P2030 | ||
PrismaError_P2031 | ||
PrismaError_P2033 | ||
PrismaError_P2034 | ||
PrismaError_P2035 | ||
PrismaError_P2036 | ||
PrismaError_P2037 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
PrismaError_P2000 = "列{column_name}提供的值太长" | ||
PrismaError_P2001 = "在where条件({model_name}.{argument_name} = {argument_value})中搜索的记录不存在" | ||
PrismaError_P2002 = "约束{target}出现重复数据" | ||
PrismaError_P2003 = "字段{field_name}上的外键约束失败" | ||
PrismaError_P2004 = "数据库上的约束失败: {database_error}" | ||
PrismaError_P2005 = "存储在数据库中字段{field_name}的值{field_value}对字段类型无效" | ||
PrismaError_P2006 = "为{model_name}字段{field_name}提供的值{field_value}无效" | ||
PrismaError_P2007 = "数据验证错误: {database_error}" | ||
PrismaError_P2008 = "未能在{query_position}解析查询: {query_parsing_error}" | ||
PrismaError_P2009 = "无法在{query_position}验证查询: {query_validation_error}" | ||
PrismaError_P2010 = "原始查询失败。代码: {code}。消息: {message}" | ||
PrismaError_P2011 = "{constraint}上的空约束违规" | ||
PrismaError_P2012 = "在{path}缺少一个必需值" | ||
PrismaError_P2013 = "缺少{object_name}上字段{field_name}所需的参数{argument_name}" | ||
PrismaError_P2014 = "您试图进行的更改将违反{model_a_name}和{model_b_name}模型之间的必要关系'{relation_name}'" | ||
PrismaError_P2015 = "找不到相关记录。{details}" | ||
PrismaError_P2016 = "查询解释错误。{details}" | ||
PrismaError_P2017 = "{parent_name}和{child_name}模型之间的关系{relation_name}的记录没有连接" | ||
PrismaError_P2018 = "找不到所需的连接记录。{details}" | ||
PrismaError_P2019 = "输入错误。{details}" | ||
PrismaError_P2020 = "该类型的值超出范围。{details}" | ||
PrismaError_P2021 = "当前数据库中不存在表{table}" | ||
PrismaError_P2022 = "当前数据库中不存在{column}列" | ||
PrismaError_P2023 = "不一致的列数据: {message}" | ||
PrismaError_P2024 = "从连接池中获取新连接的时已过(当前连接池超时: {timeout},连接限制: {connection_limit})。(更多信息: http://pris.ly/d/connection-pool)" | ||
PrismaError_P2025 = "依赖一个或多个的记录找到。{cause}" | ||
PrismaError_P2026 = "当前数据库提供程序不支持查询使用的功能: {feature}" | ||
PrismaError_P2027 = "查询执行期间数据库出现多个错误: {errors}" | ||
PrismaError_P2028 = "事务API错误: {error}" | ||
PrismaError_P2029 = "查询参数限制超过错误: {message}" | ||
PrismaError_P2030 = "找不到用于搜索的全文索引,请尝试在您的模式中添加@@fulltext([Fields...])" | ||
PrismaError_P2031 = "Prisma需要执行事务,这需要您的MongoDB服务器作为副本集运行。查看详情: https://pris.ly/d/mongodb-replica-set" | ||
PrismaError_P2033 = "查询中使用的数字不适合64位有符号整数。如果您试图存储大整数,请考虑使用BigInt作为字段类型" | ||
PrismaError_P2034 = "由于写入冲突或死锁,事务失败。请重试您的事务" | ||
PrismaError_P2035 = "数据库上的断言违规: {database_error}" | ||
PrismaError_P2036 = "外部连接器错误(id {id})" | ||
PrismaError_P2037 = "打开的数据库连接太多: {message}" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Submodule wundergraphGitSubmodule
updated
2 files
+25 −17 | pkg/datasources/database/datasource.go | |
+46 −0 | pkg/datasources/database/datasource_i18n.go |