在一个项目中,我将graphql-java和spring boot与postgreSQL数据库一起使用。现在,我想使用3.0.0版中发布的订阅功能。不幸的是,有关使用订阅功能的信息不是很成熟。
如何通过订阅实现实时功能graphql-java?
我正在使用 asp.net MVC 2 和 Ninject 2。
设置非常简单。控制器调用调用存储库的服务。
在我的控制器中,我使用注入来实例化服务类,没有任何问题。但服务类不会实例化存储库,从而给我 NullReferenceException。
public class BaseController : Controller
{
[Inject]
public IRoundService roundService { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这有效。但这并不...
public class BaseService
{
[Inject]
public IRoundRepository roundRepository { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
当我尝试在 RoundService 类中使用 roundRepository 时,出现 NullReferenceException。
IList<Round> rounds = roundRepository.GetRounds( );
Run Code Online (Sandbox Code Playgroud)
模块类 -
public class ServiceModule : NinjectModule
{
public override void Load( )
{
Bind<IRoundService>( ).To<RoundService>( ).InRequestScope( );
}
}
public class RepositoryModule : NinjectModule
{
public override void Load( …Run Code Online (Sandbox Code Playgroud) 我正在运行 Ruby on Rails 网站,目前正在使用 Rails 的 ActiveStorage 来存储我的图像和视频。
我正在使用基于 AWS 的存储空间 (DigitalOcean),他们最近推出了对自定义 CDN 支持的支持。my-space.nyc3.digitalocean.com意思是,我不会引用 ,而是引用assets.akinyele.ca。
一切都已在我的 DigicalOcean 仪表板上设置完毕。但我想知道是否可以assets.akinyele.ca在 ActiveStorage 上使用。
我尝试不指定bucket自动失败的字段,因为 ActiveStorage API 看起来需要该字段,并使用它来构建空间存储服务的 URL。我也尝试指定endpointto assets.akinyele.ca,但这给了我my-space.assets.akinyele.ca。
这是配置的一部分:
# config/storage.yml
local: #
development: #
# This is what I need to replace, and this is was I am using right now.
amazon:
service: S3
access_key_id: <%= ENV["TANOSHIMU_SPACE_ACCESS_KEY_ID"] %>
secret_access_key: <%= ENV["TANOSHIMU_SPACE_SECRET_ACCESS_KEY"] %>
region: nyc3
bucket: my space …Run Code Online (Sandbox Code Playgroud) 我使用了在 Rails 中使用 Javascript指南中的remote: true习语:
# new.html.slim
= form_for @thing, remote: true do |f|
f.text_field :whatever
f.submit 'Submit'
Run Code Online (Sandbox Code Playgroud)
# thing_controller.rb
layout 'foo'
def create
end
Run Code Online (Sandbox Code Playgroud)
# create.js.erb
alert('foobar')
Run Code Online (Sandbox Code Playgroud)
这失败了,因为由于create.js.erb某种原因在 'foo' 布局内呈现并返回为 html,而不是 javascript,尽管该请求被正确处理为 Javascript:
Processing by ThingsController#create as JS
Parameters: {"utf8"=>"?", "commit"=>"Submit"}
Rendered things/create.js.erb (0.6ms)
Run Code Online (Sandbox Code Playgroud)
(无论我respond_to在控制器操作中是否有显式格式块,问题都是一样的。)
如此处和此处所述,包括render layout: false在控制器操作中解决了问题:
# thing_controller.rb
layout 'foo'
def create
render layout: false
end
Run Code Online (Sandbox Code Playgroud)
但为什么我需要render layout: false这里?为什么 Rails 在 …
在我的 Rails 5.2.2 应用程序中,我使用 Active Storage 附加logos到profiles:
class Profile < ApplicationRecord
has_many_attached :logos
end
Run Code Online (Sandbox Code Playgroud)
如何测试更新时个人资料中是否附加了新徽标?
现在,我正在检查logos控制器中是否有一个工作正常的参数:
class ProfileController < ApplicationController
def update
if params[:profile][:logos].present?
@profile.logo_active = true # This is the important attribute I need to set
end
if @profile.update(profile_params)
flash[:success] = "Profile updated."
redirect_to profile_path
end
end
end
Run Code Online (Sandbox Code Playgroud)
有没有办法在模型中执行相同的操作,即检查附件是否实际上是新的,然后logo_active根据该附件设置属性?
我尝试了 Rails 的new_record?方法,但没有成功。
我正在尝试检索所有expired_at为零且expired_at大于当前时间的记录。
我试过这个:
PriceRule.where("expired_at > ? OR expired_at = ?", DateTime.now, nil)
Run Code Online (Sandbox Code Playgroud)
但这只会返回expired_at大于DateTime.now. 为什么nil被忽视?
将 Rails 与 ActiveRecord(和 PostgreSQL)一起使用时,执行“简单”查询会为它们添加一个名称,例如调用
Article.all
# => Article Load (2.6ms) SELECT "articles".* FROM "articles"
Run Code Online (Sandbox Code Playgroud)
命名查询Article Load。但是,当执行稍微复杂的查询时,不会生成名称,例如
Article.group(:article_group_id).count
# => (1.2ms) SELECT COUNT(*) AS count_all, "articles"."article_group_id" AS articles_article_group_id FROM "articles" GROUP BY "articles"."article_group_id"
Run Code Online (Sandbox Code Playgroud)
如果使用以下execute方法执行自定义查询,我可以添加一个名称:
ActiveRecord::Base.connection.execute("SELECT * FROM articles", "My custom query name")
# => My custom query name (2.5ms) SELECT * FROM articles
Run Code Online (Sandbox Code Playgroud)
但是有没有办法将自定义名称添加到使用 ActiveRecord 方法构建的查询中?
如果您想知道为什么:该名称对于所有类型的监控都很有用,例如在 AppSignal 中查看慢查询时。
问题
由于这个问题,我不得不将我的 RoR 应用程序升级到 Rails 7 。进行此升级时,由于 Rails 使用本机解密尝试解密字段,因此无法再读取使用Lockbox gem加密的 db 列。我在 GitHub 上将它作为一个问题发布,但我也想知道是否有其他人有解决方案将数据从一种加密格式迁移到新的本机加密中,该加密将随 Rails 7.0 一起提供(目前 Rails 的稳定版本是6.1.4 和 Rails 7.0.alpha 在 GitHub 的主分支上)
代码
应用程序/模型/journal_entry.rb
class JournalEntry < ApplicationRecord
belongs_to :prayer_journal
encrypts :content
validates :content, presence: true
end
Run Code Online (Sandbox Code Playgroud)
数据库/模式.rb
create_table "journal_entries", force: :cascade do |t|
t.bigint "prayer_journal_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.text "content_ciphertext"
t.index ["prayer_journal_id"], name: "index_journal_entries_on_prayer_journal_id"
end
Run Code Online (Sandbox Code Playgroud)
第一个日志条目的控制台输出
#<JournalEntry:0x00007f95364745c8 …Run Code Online (Sandbox Code Playgroud) 假设我们有 3 个表:
products (title, product_type_id)
product_types (title)
product_type_options (product_type_id, size)
Run Code Online (Sandbox Code Playgroud)
我想加载产品、其类型以及仅特定的product_type_options ( product_type_options.size = 'XL')
Rails 中是否可以不用 N+1 查询?
就像是:
Product.includes( product_type: [product_type_options] )
.where("product_type_options.size = 'XL'")
Run Code Online (Sandbox Code Playgroud)
我无法让它与where参数一起工作。任何想法?
Rails 5.1 将主键的默认类型从integer 更改为 bigint。我们错过了这一点,现在我们得到了整数和 bigint 的混合结果。
我们应该在整数溢出再次袭击我们之前摆脱困境(其他项目,其他故事)。
我很乐意看到一个聪明的迁移脚本改变一切
列出整数类型主键的方法将是一个好的开始。
sql ×2
apm ×1
asp.net ×1
asp.net-mvc ×1
cdn ×1
encryption ×1
graphql ×1
graphql-java ×1
java ×1
javascript ×1
lockbox-3 ×1
ninject ×1
ninject-2 ×1
postgresql ×1
spring-boot ×1