我有下表MyTable
:
id ? value_two ? value_three ? value_four
???????????????????????????????????????????
1 ? a ? A ? AA
2 ? a ? A2 ? AA2
3 ? b ? A3 ? AA3
4 ? a ? A4 ? AA4
5 ? b ? A5 ? AA5
Run Code Online (Sandbox Code Playgroud)
我想查询{ value_three, value_four }
按组分组的对象数组value_two
.value_two
应该在结果中独立存在.结果应如下所示:
value_two ? value_four
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
a ? [{"value_three":"A","value_four":"AA"}, {"value_three":"A2","value_four":"AA2"}, {"value_three":"A4","value_four":"AA4"}]
b ? [{"value_three":"A3","value_four":"AA3"}, {"value_three":"A5","value_four":"AA5"}]
Run Code Online (Sandbox Code Playgroud)
它是否使用json_agg()
或无关紧要array_agg()
.
然而,我能做的最好的事情是:
with MyCTE as ( select …
Run Code Online (Sandbox Code Playgroud) 我在我的数据库中有几个小实体,我表示为包含两列的小表:id和name.此类实体的示例:国家,大陆.
我应该创建一个枚举类型,只要这些实体的名称无关紧要?
我想计算异步函数(async
/ await
)在JavaScript中花费了多长时间。
一个可以做:
const asyncFunc = async function () {};
const before = Date.now();
asyncFunc().then(() => {
const after = Date.now();
console.log(after - before);
});
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用,因为promise回调在新的微任务中运行。即,在asyncFunc()
的开始和结束之间then(() => {})
,将首先触发任何已排队的微任务,并考虑其执行时间。
例如:
const asyncFunc = async function () {};
const slowSyncFunc = function () {
for (let i = 1; i < 10 ** 9; i++) {}
};
process.nextTick(slowSyncFunc);
const before = Date.now();
asyncFunc().then(() => {
const after = Date.now();
console.log(after - before);
});
Run Code Online (Sandbox Code Playgroud)
这会1739 …
如何使用自签名证书对https:// URL进行Javascript XMLHttpRequest,客户知道该证书是合法的?
我尝试触发XMLHttpRequest的错误事件.
我似乎错过了Javascript中构造函数链继承的一些东西,包含本机对象.例如 :
function ErrorChild(message) { Error.call(this, message); }
ErrorChild.prototype = Object.create(Error.prototype);
var myerror = new ErrorChild("Help!");
Run Code Online (Sandbox Code Playgroud)
为什么myerror.message
定义为""
这些陈述之后?我希望Error构造函数将其定义为"Help!" (并覆盖默认值Error.prototype.message
),就像我在做的那样:
var myerror = new Error("Help!")
Run Code Online (Sandbox Code Playgroud)
非常感谢 !
我有以下指令:
angular.module("example_module", [])
.directive("mydirective", function() {
return {
scope: { data: "@mydirective" }
compile: function(element) {
element.html('{{example}}');
return function($scope) {
$scope.example = $scope.data + "!";
};
}
};
});
Run Code Online (Sandbox Code Playgroud)
和以下HTML代码:
<!DOCTYPE html>
<html ng-app="example_module">
<head>
<meta charset="utf-8">
<title>Example title</title>
<script src="lib/angular/angular.min.js"></script>
<script src="js/example.js"></script>
</head>
<body>
<div mydirective="Hello world"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我希望编译指令Hello world!
,但它编译为空字符串.scope
创造一个似乎无法达到的孤立范围{{example}}
.
我想知道创建的新HTML代码如何compile()
访问链接功能$scope
.
Amazon S3 将我的二进制数据解释为非 UTF-8,并在我写入存储桶时对其进行修改。
使用官方 s3 Javascript 客户端的示例:
var png_file = new Buffer( "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==", "base64" ).toString( "binary" );
s3.putObject( {
Bucket: bucket,
Key: prefix + file,
ContentType: "image/png;charset=utf-8",
CacheControl: "public, max-age=31536000",
Body: png_file
// , ContentLength: png_file.length
}, function( e ){
if ( e ) {
console.log( e );
} else {
s3.getObject( {
Bucket: bucket,
Key: prefix + file
}, function( e, v ) {
if ( e ) {
console.log( e )
} else {
console.log( v.ContentLength ); …
Run Code Online (Sandbox Code Playgroud) 我有下表One
:
id ? value
????????????
1 ? a
2 ? b
Run Code Online (Sandbox Code Playgroud)
而且Two
:
id ? value
?????????????
10 ? a
20 ? a
30 ? b
40 ? a
50 ? b
Run Code Online (Sandbox Code Playgroud)
One.value
有一个独特的约束,但没有Two.value
(一对多的关系).
其中SQL(Postgres的)查询将检索作为数组的id
第Two
其值匹配One.value
?我要找的结果是:
id ? value
?????????????????????
{10,20,40} ? a
{30,50} ? b
Run Code Online (Sandbox Code Playgroud) javascript ×3
sql ×3
arrays ×2
postgresql ×2
amazon-s3 ×1
angularjs ×1
async-await ×1
asynchronous ×1
benchmarking ×1
binary ×1
database ×1
enums ×1
https ×1
inheritance ×1
json ×1