此处将为大家介绍关于Aorm又进步了,目前已支持MySQL,MSSQL,Postgres,Sqlite3,并且支持子查询的详细内容,并且为您解答有关mysql支持arm吗的相关问题,此外,我们还将为您
此处将为大家介绍关于Aorm又进步了,目前已支持MySQL,MSSQL,Postgres,Sqlite3,并且支持子查询的详细内容,并且为您解答有关mysql支持arm吗的相关问题,此外,我们还将为您介绍关于Bundler::GemRequireError 和 Gem Load Error 是:AddDllDirectory 从 Sqlite3 切换到 Postgres 时失败、Django TestCase 适用于 Sqlite3 - 不适用于 Postgres、Docker Compose 无法从用户“postgres”的数据库 (jdbc:postgresql://db:5432/postgres) 获取连接:连接尝试失败、Docker-compose postgres 错误:致命:用户“postgres”的有用信息。
本文目录一览:- Aorm又进步了,目前已支持MySQL,MSSQL,Postgres,Sqlite3,并且支持子查询(mysql支持arm吗)
- Bundler::GemRequireError 和 Gem Load Error 是:AddDllDirectory 从 Sqlite3 切换到 Postgres 时失败
- Django TestCase 适用于 Sqlite3 - 不适用于 Postgres
- Docker Compose 无法从用户“postgres”的数据库 (jdbc:postgresql://db:5432/postgres) 获取连接:连接尝试失败
- Docker-compose postgres 错误:致命:用户“postgres”
Aorm又进步了,目前已支持MySQL,MSSQL,Postgres,Sqlite3,并且支持子查询(mysql支持arm吗)
hi,各位golang的朋友,我很高兴的告诉你们,Aorm又进步了。
Aorm是什么
Aorm是一个基于go语言的数据库操作库,可以帮助你更方便的进行数据库操作。
它最大的特点是支持空值查询和更新,以及支持sql的链式操作,特别类似于php相关的orm操作
这里是之前发过的一个文档
想早点下班?试试Aorm库吧,更方便的进行Go数据库操作 - 掘金 (juejin.cn)
这是具体的项目地址
tangpanqing/aorm: Operate Database So Easy For GoLang Developer (github.com)
在最近的一个星期左右,我将它进行了升级。
之前只支持MySQL
,目前已经支持MySQL
, MSSQL
, Postgres
, Sqlite3
等四大数据库
之前不支持子查询
,目前已经支持
示例
一般情况下的写入
如果你使用MySQL
,Sqlite3
数据库,可以直接使用如下的代码,来进行一次插入
id, errInsert := aorm.Use(db).Debug(true).Insert(&Person{
Name: null.StringFrom("Alice"),
Sex: null.BoolFrom(false),
Age: null.IntFrom(18),
Type: null.IntFrom(0),
CreateTime: null.TimeFrom(time.Now()),
Money: null.FloatFrom(100.15),
Test: null.FloatFrom(200.15987654321987654321),
})
if errInsert != nil {
fmt.Println(errInsert)
}
fmt.Println(id)
它产生的sql如下
INSERT INTO person (name,sex,age,type,create_time,money,test) VALUES (?,?,?,?,?,?,?)
Alice false 18 0 2022-12-07 10:10:26.1450773 +0800 CST m=+0.031808801 100.15 200.15987654321987
MSSQL与Postgres的特殊性
如果你使用MSSQL
,Postgres
数据库,需要增加一个Driver
操作,以明确的告诉Aorm,这里是MSSQL
或者Postgres
,Aorm会对sql做一些修改,例如
id, errInsert := aorm.Use(db).Debug(true).Driver("mssql").Insert(&Person{
....
})
它产生的sql如下
INSERT INTO person (name,sex,age,type,create_time,money,test) VALUES (?,?,?,?,?,?,?); select ID = convert(bigint, SCOPE_IDENTITY())
Alice false 18 0 2022-12-07 10:10:26.1450773 +0800 CST m=+0.031808801 100.15 200.15987654321987
你可能已经注意到,生成的sql里,加上了
select ID = convert(bigint, SCOPE_IDENTITY())
这是因为mssql
默认情况下,并不会返回最后插入的记录id,只有加上这一句sql,进行一次查询才能得到
另外Postgres
也有类似的情况,只不过它加的sql代码是
returning id
支持子查询
子查询是非常重要的功能,可以极大的方便查询,目前aorm已经可以支持
将子查询用在字段上
var listByFiled []PersonWithArticleCount
sub := aorm.Sub().Table("article").SelectCount("id", "article_count_tem").WhereRaw("person_id", "=person.id")
err := aorm.Use(db).Debug(false).
Driver(driver).
SelectExp(&sub, "article_count").
Select("*").
Where(&Person{Age: null.IntFrom(18)}).
GetMany(&listByFiled)
if err != nil {
panic(driver + " testSelectWithSub " + "found err:" + err.Error())
}
你可能已经注意到
sub := aorm.Sub().Table("article").SelectCount("id", "article_count_tem").WhereRaw("person_id", "=person.id")
这里定义了一个子查询,它此时并没有查询数据库哦,然后将他作为参数使用
SelectExp(&sub, "article_count").
意思很明显,上述子查询的结果,将被重命名一个新的字段 article_count
,最终生成的sql为
SELECT *,(SELECT count(id) AS article_count_tem FROM article WHERE person_id=person.id) AS article_count FROM person WHERE age = ?
18
将子查询用在查询条件上
var listByFiled []Person
sub := aorm.Sub().Table("article").Select("person_id").GroupBy("person_id").HavingGt("count(person_id)", 0)
err := aorm.Use(db).Debug(false).
Table("person").
Driver(driver).
WhereIn("id", &sub).
GetMany(&listByFiled)
if err != nil {
panic(driver + " testWhereWithSub " + "found err:" + err.Error())
}
如你所见
sub := aorm.Sub().Table("article").Select("person_id").GroupBy("person_id").HavingGt("count(person_id)", 0)
这里定义了一个子查询,它在如下的代码块被使用
WhereIn("id", &sub).
意思很明显,上述子查询的结果,将被用作where的一个条件,它产生的sql如下
SELECT * FROM person WHERE id IN (SELECT person_id FROM article GROUP BY person_id Having count(person_id) > ?)
0
总结
支持了更多的数据库,Aorm拓展了更多的应用范围
支持了子查询,Aorm更强大了
项目地址
tangpanqing/aorm: Operate Database So Easy For GoLang Developer (github.com)
给个 ⭐ 吧,如果这个项目帮助到你
Bundler::GemRequireError 和 Gem Load Error 是:AddDllDirectory 从 Sqlite3 切换到 Postgres 时失败
如何解决Bundler::GemRequireError 和 Gem Load Error 是:AddDllDirectory 从 Sqlite3 切换到 Postgres 时失败
我在 rails 中有一个与 sqlite3 一起使用的项目。我必须搬到 POSTGRES,因为 Heroku 需要这样做。
按照文档:https://devcenter.heroku.com/articles/sqlite3#running-rails-on-postgres,这是我所做的:
- 更改了 Gemfile:
从gem ''sqlite3''
到gem ''pg''
注意:我也试过 gem ''pg'',''~> 1.2'',''>= 1.2.3''
和 gem ''pg'',''>= 1.2.2''
。它们都返回相同的错误。
- 运行
bundle install
没有错误 - 修改了
config/database.yml
default: &default
adapter: postgresql
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: test_postgres
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: test_postgres
production:
<<: *default
database: test_postgres
- 根据文档,
一旦你安装了 pg gem 并迁移了你的 config/database.yml
我尝试了返回的 rails db:migrate
:
Bundler::GemRequireError: There was an error while trying to load the gem ''pg''.
Gem Load Error is: AddDllDirectory Failed for D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/x64-mingw32
Backtrace for gem load error is:
...
注意:同样的错误显示在 rake db:migrate
rails s
打印出同样的错误:
D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:69:in `rescue in block (2 levels) in require'': There was an error while trying to load the gem ''pg''. (Bundler::GemRequireError)
Gem Load Error is: AddDllDirectory Failed for D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/x64-mingw32
Backtrace for gem load error is:
D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/dll_directory.rb:83:in `add_dll_directory_winapi''
D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/dll_directory.rb:50:in `initialize''
D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/singleton.rb:12:in `new''
D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/singleton.rb:12:in `add_dll_directory''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:15:in `block in <main>''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:26:in `rescue in <main>''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:4:in `<main>''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require''
D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:66:in `block (2 levels) in require''
D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:61:in `each''
D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:61:in `block in require''
D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:50:in `each''
D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:50:in `require''
D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler.rb:173:in `require''
D:/Fresqui/Documents/Programar/yale-citrus/config/application.rb:7:in `<main>''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2/lib/active_support/dependencies.rb:332:in `block in require''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2/lib/active_support/dependencies.rb:299:in `load_dependency''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2/lib/active_support/dependencies.rb:332:in `require''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/commands/server/server_command.rb:138:in `block in perform''
<internal:kernel>:90:in `tap''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/commands/server/server_command.rb:135:in `perform''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/command/base.rb:69:in `perform''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/command.rb:50:in `invoke''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/commands.rb:18:in `<main>''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require''
bin/rails:4:in `<main>''
Bundler Error Backtrace:
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:65:in `block (2 levels) in require''
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:61:in `each''
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:61:in `block in require''
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:50:in `each''
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:50:in `require''
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler.rb:173:in `require''
from D:/Fresqui/Documents/Programar/yale-citrus/config/application.rb:7:in `<main>''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2/lib/active_support/dependencies.rb:332:in `block in require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2/lib/active_support/dependencies.rb:299:in `load_dependency''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2/lib/active_support/dependencies.rb:332:in `require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/commands/server/server_command.rb:138:in `block in perform''
from <internal:kernel>:90:in `tap''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/commands/server/server_command.rb:135:in `perform''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/command/base.rb:69:in `perform''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/command.rb:50:in `invoke''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/commands.rb:18:in `<main>''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require''
from bin/rails:4:in `<main>''
D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/dll_directory.rb:83:in `add_dll_directory_winapi'': AddDllDirectory Failed for D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/x64-mingw32 (RubyInstaller::Runtime::DllDirectory::WinApiError)
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/dll_directory.rb:50:in `initialize''
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/singleton.rb:12:in `new''
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/ruby_installer/runtime/singleton.rb:12:in `add_dll_directory''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:15:in `block in <main>''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:26:in `rescue in <main>''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:4:in `<main>''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require''
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:66:in `block (2 levels) in require''
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:61:in `each''
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:61:in `block in require''
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:50:in `each''
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:50:in `require''
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler.rb:173:in `require''
from D:/Fresqui/Documents/Programar/yale-citrus/config/application.rb:7:in `<main>''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2/lib/active_support/dependencies.rb:332:in `block in require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2/lib/active_support/dependencies.rb:299:in `load_dependency''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2/lib/active_support/dependencies.rb:332:in `require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/commands/server/server_command.rb:138:in `block in perform''
from <internal:kernel>:90:in `tap''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/commands/server/server_command.rb:135:in `perform''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/command/base.rb:69:in `perform''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/command.rb:50:in `invoke''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/commands.rb:18:in `<main>''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require''
from bin/rails:4:in `<main>''
D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'': 126: The specified module Could not be found. - D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg_ext.so (LoadError)
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2/lib/active_support/dependencies.rb:332:in `block in require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2/lib/active_support/dependencies.rb:299:in `load_dependency''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2/lib/active_support/dependencies.rb:332:in `require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/pg-1.2.3/lib/pg.rb:5:in `<main>''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require''
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:66:in `block (2 levels) in require''
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:61:in `each''
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:61:in `block in require''
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:50:in `each''
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler/runtime.rb:50:in `require''
from D:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/bundler.rb:173:in `require''
from D:/Fresqui/Documents/Programar/yale-citrus/config/application.rb:7:in `<main>''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2/lib/active_support/dependencies.rb:332:in `block in require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2/lib/active_support/dependencies.rb:299:in `load_dependency''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/activesupport-6.1.2/lib/active_support/dependencies.rb:332:in `require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/commands/server/server_command.rb:138:in `block in perform''
from <internal:kernel>:90:in `tap''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/commands/server/server_command.rb:135:in `perform''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/command/base.rb:69:in `perform''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/command.rb:50:in `invoke''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/railties-6.1.2/lib/rails/commands.rb:18:in `<main>''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi''
from D:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require''
from bin/rails:4:in `<main>''
我找不到关于 gem 被弃用的任何信息,文档中没有任何内容,也没有多少帖子出现相同的错误。有什么线索吗?
解决方法
这是原始答案 link,每个 pacman 安装 postgresql:
ridk exec pacman -S mingw-w64-x86_64-postgresql
- 重新安装 pg gem
gem install pg
- 运行数据库设置脚本
rails db:setup
Django TestCase 适用于 Sqlite3 - 不适用于 Postgres
如何解决Django TestCase 适用于 Sqlite3 - 不适用于 Postgres
我想弄清楚为什么我的测试适用于 sqlite3
但不适用于 Postgres
。
导入操作系统
from django.conf import settings
from django.test import TestCase
from products.factory import ProductFactory
from products.models import Product,Organisation
from products.services.imports import ImportService
from users.factory import UserFactory,OrganisationFactory
from users.models import User
class ProductTestCase(TestCase):
@classmethod
def setUpTestData(cls) -> None:
cls.org = OrganisationFactory.create(name=''My organisation'')
cls.user = User.objects.create_user(''peter'',''xxxxxxxx'')
cls.user.organisation = cls.org
cls.product = ProductFactory.create(title=''Title'',created_by=cls.user,organisation=cls.org)
def test_product_has_organisation(self) -> None:
self.assertTrue(self.product.organisation,''Product has no organisation'')
当使用 Postgres
运行它时,它会引发:
ERROR: test_product_has_organisation (products.tests.test_product.ProductTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/milano/PycharmProjects/.virtualenvs/markethelper_api/lib/python3.9/site-packages/django/db/backends/utils.py",line 82,in _execute
return self.cursor.execute(sql)
psycopg2.errors.Foreignkeyviolation: insert or update on table "products_product" violates foreign key constraint "products_product_updated_by_id_33940c75_fk_users_user_id"
DETAIL: Key (updated_by_id)=(19) is not present in table "users_user".
Product.updated_by:
updated_by = CurrentUserField(''users.User'',on_delete=models.CASCADE,related_name=''updated_products'',null=True,blank=True,verbose_name=''Updated by'',on_update=True)
你知道问题出在哪里吗?
Docker Compose 无法从用户“postgres”的数据库 (jdbc:postgresql://db:5432/postgres) 获取连接:连接尝试失败
如何解决Docker Compose 无法从用户“postgres”的数据库 (jdbc:postgresql://db:5432/postgres) 获取连接:连接尝试失败
问题:
我正在使用 Docker Compose 创建两个容器:一个带有 Postgres 数据库,另一个带有 Flyway。目标是使用 Flyway 将脚本迁移到 Postgres 数据库实例。当我运行 docker-compose up 时,出现以下错误:
Unable to obtain connection from database (jdbc:postgresql://db:5432/) for user ''luke_skywalker'': The connection attempt Failed.
我的代码在下面,感谢您的帮助!
这是我的 docker-compose.yml:
version: "3.7"
services:
postgres_db:
image: postgres:11.3
container_name: postgres_database
restart: always
# map host port to default postgres port of the contianer; note host port was randomly chose from ports that are unassinged
environment:
POSTGRES_USER: ${postgres_user}
POSTGRES_PASSWORD: ${postgres_password}
ports:
- 11102:5432
flyway_migration:
#https://github.com/flyway/flyway-docker
image: flyway/flyway
container_name: flyway
environment:
FLYWAY_PASSWORD: ${postgres_password}
FLYWAY_USER: ${postgres_user}
volumes:
#create flyway supported volume in the container that has our migration scripts; https://github.com/flyway/flyway-docker
- .\\migration_scripts:/flyway/sql
#change back to 60
command: -url=jdbc:postgresql://db:5432/ -connectRetries=1 migrate -X
depends_on:
- postgres_db
这里是完整的错误信息:
Attaching to postgres_database,flyway
postgres_database | 2021-05-27 03:23:59.359 UTC [1] LOG: listening on IPv4 address "0.0.0.0",port 5432
postgres_database | 2021-05-27 03:23:59.359 UTC [1] LOG: listening on IPv6 address "::",port 5432
postgres_database | 2021-05-27 03:23:59.365 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGsql.5432"
postgres_database | 2021-05-27 03:23:59.385 UTC [23] LOG: database system was shut down at 2021-05-27 03:19:05 UTC
postgres_database | 2021-05-27 03:23:59.389 UTC [1] LOG: database system is ready to accept connections
flyway | DEBUG: Loading config file: /flyway/conf/flyway.conf
flyway | DEBUG: Unable to load config file: /flyway/flyway.conf
flyway | DEBUG: Unable to load config file: /flyway/flyway.conf
flyway | DEBUG: Adding location to classpath: /flyway/drivers/jna-4.5.2.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/msal4j-1.10.0.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/mssql-jdbc-9.2.1.jre8.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/jna-platform-4.5.2.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/postgresql-42.2.19.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/hsqldb-2.5.1.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/derbyclient-10.15.2.0.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/mysql-connector-java-8.0.24.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/derbytools-10.15.2.0.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/jaybird-jdk18-3.0.10.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/google-cloud-spanner-jdbc-2.0.2.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/aws-secretsmanager-jdbc-1.0.6.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/derbyshared-10.15.2.0.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/sNowflake-jdbc-3.13.1.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/jtds-1.3.1.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/derby-10.15.2.0.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/mariadb-java-client-2.7.2.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/google-cloud-storage-1.113.13.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/sqlite-jdbc-3.34.0.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/ojdbc8-19.6.0.0.jar
flyway | DEBUG: Adding location to classpath: /flyway/drivers/h2-1.4.200.jar
flyway | DEBUG: Using configuration:
flyway | DEBUG: flyway.connectRetries -> 1
flyway | DEBUG: flyway.jarDirs -> /flyway/jars
flyway | DEBUG: flyway.locations -> filesystem:sql
flyway | DEBUG: flyway.password -> *************
flyway | DEBUG: flyway.url -> jdbc:postgresql://db:5432/postgres
flyway | DEBUG: flyway.user -> luke_skywalker
flyway | DEBUG: Multiple databases found that handle url ''jdbc:postgresql://db:5432/postgres'': CockroachDB,Postgresql
flyway | DEBUG: Scanning for classpath resources at ''classpath:db/callback'' ...
flyway | DEBUG: Determining location urls for classpath:db/callback using ClassLoader java.net.urlclassloader@18be83e4 ...
flyway | DEBUG: Unable to resolve location classpath:db/callback.
flyway | Flyway Community Edition 7.9.1 by Redgate
flyway | DEBUG: AWS SDK available: false
flyway | DEBUG: Google Cloud Storage available: false
flyway | DEBUG: Scanning for filesystem resources at ''sql''
flyway | DEBUG: Scanning for resources in path: sql (sql)
flyway | DEBUG: Found filesystem resource: sql/V1__initial.sql
flyway | WARNING: Connection error: The connection attempt Failed. (Caused by db) retrying in 1 sec...
flyway | ERROR: Unexpected error
flyway | org.flywaydb.core.internal.exception.FlywaysqlException:
flyway | Unable to obtain connection from database (jdbc:postgresql://db:5432/postgres) for user ''luke_skywalker'': The connection attempt Failed.
flyway | ----------------------------------------------------------------------------------------------------------------------------------------
flyway | sql State : 08001
flyway | Error Code : 0
flyway | Message : The connection attempt Failed.
flyway |
flyway | at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:68)
flyway | at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:68)
flyway | at org.flywaydb.core.Flyway.execute(Flyway.java:510)
flyway | at org.flywaydb.core.Flyway.migrate(Flyway.java:170)
flyway | at org.flywaydb.commandline.Main.executeOperation(Main.java:227)
flyway | at org.flywaydb.commandline.Main.main(Main.java:148)
flyway | Caused by: org.postgresql.util.PsqlException: The connection attempt Failed.
flyway | at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:315)
flyway | at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)
flyway | at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:223)
flyway | at org.postgresql.Driver.makeConnection(Driver.java:465)
flyway | at org.postgresql.Driver.connect(Driver.java:264)
flyway | at org.flywaydb.core.internal.jdbc.DriverDataSource.getConnectionFromDriver(DriverDataSource.java:263)
flyway | at org.flywaydb.core.internal.jdbc.DriverDataSource.getConnection(DriverDataSource.java:227)
flyway | at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:54)
flyway | ... 5 more
flyway | Caused by: java.net.UnkNownHostException: db
flyway | at java.base/java.net.AbstractPlainSocketImpl.connect(UnkNown Source)
flyway | at java.base/java.net.socksSocketImpl.connect(UnkNown Source)
flyway | at java.base/java.net.socket.connect(UnkNown Source)
flyway | at org.postgresql.core.PGStream.createSocket(PGStream.java:231)
flyway | at org.postgresql.core.PGStream.<init>(PGStream.java:95)
flyway | at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:98)
flyway | at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:213)
flyway | ... 12 more
flyway exited with code 1
解决方法
正如异常消息所说:
Caused by: java.net.UnknownHostException: db [...]
您尝试通过 db
主机连接到 postgres:
-url=jdbc:postgresql://db:5432/ -connectRetries=1 migrate -X
但是您将 postgres 别名设置为 postgres_db
。只需将 flyway 的连接 url 更改为:
-url=jdbc:postgresql://postgres_db:5432/ -connectRetries=1 migrate -X
Docker-compose postgres 错误:致命:用户“postgres”
如何解决Docker-compose postgres 错误:致命:用户“postgres”
我在 docker-compose 中使用 postgres 时出错。当我使用 docker-compose up -d
启动 docker-compose 时,一切正常。但1-2天后,错误发生。我注意到,当它发生时,linux 机器变得非常慢,我无法对 docker 进行任何操作。我试过:sudo systemctl restart docker.service
重新启动 docker 守护进程,但它只是停止并且什么也不做。但是当我重新启动机器时,滞后消失了。我认为 config(docker-compose.yml
) 有问题。
这是我的docker-compose.yml
:
volumes:
common-volume:
postgres:
services:
Nginx:
container_name: Nginx
image: Nginx:latest
ports:
- ''80:80''
volumes:
- ./Nginx.conf:/etc/Nginx/Nginx.conf:ro
networks:
app_net:
ipv4_address: 10.5.1.5
postgres:
container_name: docker-postgres
ports:
- ${POSTGRES_PORT:-5432}:${POSTGRES_PORT:-5432}
restart: always
environment:
- POSTGRES_DB=${DB_NAME}
- POSTGRES_USER=${DB_USERNAME}
- POSTGRES_PASSWORD=${DB_PASSWORD}
- PGDATA=/var/lib/postgresql/data
image: postgres
networks:
app_net:
ipv4_address: 10.5.0.8
volumes:
- postgres:/var/lib/postgresql/data/
common:
container_name: docker-common
build: ./common
volumes:
- common-volume:/usr/src/common
auth_service:
container_name: docker-auth-service
build: ./auth-service
restart: always
environment:
- DB_HOST=postgres
- DB_USERNAME=postgres
- DB_NAME=postgres
- DB_PASSWORD=postgres
- NODE_ENV=production
- REdis_HOST=10.5.0.7
env_file:
- .env
volumes:
- common-volume:/usr/src/common
expose:
- "8080"
depends_on:
- postgres
links:
- postgres
networks:
app_net:
ipv4_address: 10.5.0.5
redis:
container_name: redis
image: ''redis:4-alpine''
expose:
- "6379"
networks:
app_net:
ipv4_address: 10.5.0.7
networks:
app_net:
ipam:
config:
- subnet: 10.5.0.0/16
我们今天的关于Aorm又进步了,目前已支持MySQL,MSSQL,Postgres,Sqlite3,并且支持子查询和mysql支持arm吗的分享就到这里,谢谢您的阅读,如果想了解更多关于Bundler::GemRequireError 和 Gem Load Error 是:AddDllDirectory 从 Sqlite3 切换到 Postgres 时失败、Django TestCase 适用于 Sqlite3 - 不适用于 Postgres、Docker Compose 无法从用户“postgres”的数据库 (jdbc:postgresql://db:5432/postgres) 获取连接:连接尝试失败、Docker-compose postgres 错误:致命:用户“postgres”的相关信息,可以在本站进行搜索。
本文标签: