我想where()在我的查询中添加一个子句,但有条件.具体来说,我希望只有在URL中传递了一个特定的querystring参数时才添加它.这是可能的,如果可以的话,我该怎么做呢?
router.get('/questions', function (req, res) {
knex('questions')
.select('question', 'correct', 'incorrect')
.limit(50)
.where('somecolumn', req.query.param) // <-- only if param exists
.then(function (results) {
res.send(results);
});
});
Run Code Online (Sandbox Code Playgroud) 我有一个Windows Server 2008(64位)框,我正在开发.我已经安装了Visual Studio 2010和System.Data.SQLite(来自sqlite.phxsoftware.com).我的问题是,前者没有看到后者.也就是说,当我转到Visual Studio中的服务器资源管理器并选择"连接到数据库"并出现"选择数据源"窗口时,SQLite不会出现在数据源列表下.有谁知道这笔交易是什么?这可能是Windows Server 2008的一个问题,因为过去我在Windows 7机箱上没有VS 2010 + System.Data.Sqlite的问题.
更新:System.Data.SQLite和System.Data.SQLite.Linq程序集显示在我的GAC中
system.data.sqlite visual-studio-2010 windows-server-2008-r2
给出以下数据库表:
WORDS
alphagram....varchar(15)
word.........varchar(15) PK
length.......int
Run Code Online (Sandbox Code Playgroud)
哪里:
我找到了一种通过SQL找到给定字母串的字谜的方法.例如,要找到AEINNRTT的字谜,这将有效:
select alphagram, word, definition
from words
where length = 8
and alphagram like '%A%'
and alphagram like '%E%'
and alphagram like '%I%'
and alphagram like '%NN%'
and alphagram like '%R%'
and alphagram like '%TT%'
Run Code Online (Sandbox Code Playgroud)
这将返回1行(对于INTRANET)
如果我想要包含已知数量的通配符,例如,INTRANET有多少单词+空白(通配符)我只需要将'长度'更改为字母总数+通配符数量
例如
select alphagram, word, definition
from words
where length = 9
and alphagram like '%A%'
and alphagram like '%E%'
and alphagram like '%I%'
and alphagram like '%NN%'
and alphagram like '%R%'
and alphagram like …Run Code Online (Sandbox Code Playgroud) 我有一个包含两列的 CSS 网格。
我可能会也可能不会在第一列内呈现内容。换句话说,列 div 将始终存在,只是有时其中可能没有内容。
当第一列中没有内容时,我不希望该列占用空间,当有内容时,我希望它的最大宽度为100px。
是否可以单独通过 CSS 网格定义来做到这一点?
#container {
display: grid;
grid-template-columns: minmax(auto, 100px) auto;
grid-gap: 5px;
height: 200px;
width: 100%;
background-color: #8cffa0;
padding: 10px;
}
#container > div {
background-color: #c0c0c0;
}Run Code Online (Sandbox Code Playgroud)
<div id="container">
<div>
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
</div>
<div>
Placeat, rerum illo eligendi, hic eum magnam quo architecto necessitatibus sunt sequi repellendus suscipit fuga tenetur atque corrupti modi saepe! Iusto, provident.
</div>
</div>Run Code Online (Sandbox Code Playgroud)
我有一个实现INotifyPropertyChanged接口的类.该类的一些属性是List类型.例如:
public List<string> Answers
{
get { return _answers; }
set
{
_answers = value;
onPropertyChanged("Answers")
}
}
...
private void onPropertyChanged(string propertyName)
{
if(this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
Run Code Online (Sandbox Code Playgroud)
如果我将一个新的List <string>分配给Answer,那么PropertyChanged事件将按预期触发; 但是如果我使用List Add方法将一个字符串字符串添加到Answer列表中,那么PropertyChanged事件就不会触发.
我正在考虑在我的类中添加一个AddAnswer()方法,该方法将处理调用列表的Add方法并从那里调用onPropertyChanged(),但这是正确的方法吗?有更优雅的方式吗?
干杯,KT
使用jQuery,确定SELECT元素中是否存在具有特定值或文本值的OPTION元素的最佳方法是什么?我已经看过各种关于如何找到所选项目的技巧,博客和方法,但我希望按值或文本值找到任何项目,无论是否选中它.
例如,给定下面的标记,使用jQuery,如何确定New Order是否在列表中?
<select id="music-groups">
<option value="001">Depeche Mode</option>
<option value="002">New Order</option>
<option value="021">AC-DC</option>
<option value="023">The Who</option>
<option value="090">The Beatles</option>
<option value="090">Bjork</option>
</select>
Run Code Online (Sandbox Code Playgroud)