小编noo*_*oga的帖子

如何在Sequel数据集上更新或插入?

我刚开始在一个非常小的Sinatra应用程序中使用Sequel.由于我只有一个数据库表,所以我不需要使用模型.

我想更新记录(如果存在)或插入新记录(如果不存在).我提出了以下解决方案:

  rec = $nums.where(:number => n, :type => t)
  if $nums.select(1).where(rec.exists)
    rec.update(:counter => :counter + 1)
  else
    $nums.insert(:number => n, :counter => 1, :type => t)
  end
Run Code Online (Sandbox Code Playgroud)

哪里$numsDB[:numbers]数据集.

我相信这种方式不是"更新或插入"行为的最优雅实现.

应该怎么做?

ruby upsert sequel

12
推荐指数
2
解决办法
1万
查看次数

C++错误:'inline'只能出现在函数上

我正在尝试使用clang ++在OS X 10.7下编译VCMI.

我配置项目是CXX=clang++因为Apple的gcc似乎没有识别所需的-std=c++0x标志.

我添加-stdlib=libc++CXXFLAGS因为没有那个铿锵甚至找不到#include <array>.

目前我有: CXXFLAGS= -std=c++0x -stdlib=libc++ -Wall -Wextra -Wcast-align -Wpointer-arith -Wno-switch -Wno-sign-compare -Wno-unused-parameter -Wc++11-extensions

问题是我得到以下错误:

clang: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior    is deprecated
clang: warning: argument unused during compilation: '-ggdb'
StdInc.h:1:9: warning: #pragma once in main file
#pragma once
        ^
In file included from StdInc.h:3:
In file included from ./../Global.h:32:
In file included from /usr/bin/../lib/c++/v1/algorithm:594:
In …
Run Code Online (Sandbox Code Playgroud)

c++ clang libc++

2
推荐指数
1
解决办法
2561
查看次数

标签 统计

c++ ×1

clang ×1

libc++ ×1

ruby ×1

sequel ×1

upsert ×1