小编cbl*_*bll的帖子

如何使用 Diesel 生成和解析原始 SQL 查询?

我正在使用 Rocket 框架测试 Rust。对于数据库,我使用 Diesel 与 MySQL 数据库交互。

通过几个例子,幕后发生了很多事情。我有一个 MySQL 数据库正在运行,其中有一个填充表,我想对其进行原始查询。

下面的代码有效:

use diesel::{prelude::*};

mod schema {
    table! {
        organization {
            id -> Nullable<Integer>,
            name -> Text,
            country -> Text,
        }
    }
}

use self::schema::organization;
use self::schema::organization::dsl::{organization as all_orgs};

#[table_name="organization"]
#[derive(Serialize, Deserialize, Queryable, Insertable, Debug, Clone)]
pub struct Organization {
    pub id: Option<i32>,
    pub name: String,
    pub country: String
}

impl Organization {
    pub fn all(conn: &MysqlConnection) -> Vec<Organization> {
        all_orgs.order(organization).load::<Organization>(conn).unwrap()
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,我不需要按任何顺序订购。事实上,我只想进行一个原始查询,SELECT id, name, country FROM organization …

mysql rust rust-diesel

5
推荐指数
1
解决办法
5844
查看次数

宣传单 - 如何有条件地为特定国家/地区着色?

我有一个离线的Leaflet地图,其中的国家/地区是从带有坐标的巨大Javascript变量中提取的.

index.html就是这样(来自codepen的一个例子,我在本地加载库):

<html>

<head>

  <title>Leaflet</title>

  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />

  <link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" />
  <script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>

</head>

<body>

  <div id="mapid" style="width: 100%; height: 800px;"></div>

</body>

</html>
Run Code Online (Sandbox Code Playgroud)

而Map.js是这样的:

var map = L.map('mapid').setView([0, 0], 2);

// Huge geojson of every country, one country sample here. 
var countries =  "type": "FeatureCollection",
"features": [{
    "type": "Feature",
    "id": "AFG",
    "properties": {
        "name": "Afghanistan"
    },
    "geometry": {
        "type": "Polygon",
        "coordinates": [
            [
                [61.210817, 35.650072],
                [62.230651, 35.270664],
                [62.984662, 35.404041], …
Run Code Online (Sandbox Code Playgroud)

javascript leaflet react-leaflet

4
推荐指数
1
解决办法
2235
查看次数

传单错误:clearLayers 不是函数

我正在使用带有 React 的 Leaflet 离线地图,我在其中手动加载countries.js了世界上每个国家/地区的GeoJSON 文件。然后,我根据从 收到的数据有条件地为每个国家/地区着色this.props.data,该数据最初有效。

但是,问题来自在新产品this.props.data进来时更新颜色。

我尝试在这两个组件中管理它:

componentWillReceiveProps(nextProps) {
    if(this.props.data) {
        let map = this.map;
        console.log(map); // It shows the leaflet object!
        console.log(nextProps.data); // It's logged
        console.log(this.props.data); // Also logged
        if (nextProps.data !== this.props.data) {
            map.clearLayers(); // Error comes here?
            console.log("New data doesn't match old!"); // This logs correctly
        }
    }
},

componentDidUpdate(prevProps, prevState) {
    if(this.props.data){
        let map = this.map;
        if (prevProps.data !== this.props.data) {
            L.geoJson(this.countries, { // from import
            }).addTo(map);
         } …
Run Code Online (Sandbox Code Playgroud)

javascript leaflet reactjs

4
推荐指数
1
解决办法
4955
查看次数

IDEA:未选择Grails SDK

如何使用 IntelliJ IDEA 设置 Grails?我有终极版。sdkman安装了 Grails,/home/user/.sdkman/candidates/grails/current/bin/grails 但如果我选择该文件夹作为 SDK,IDEA 会显示:The selected directory is not a valid home for Grails SDK

如何使用 Grails 建立 IDEA 项目?

grails -version从终端向我提供以下信息:

| Grails Version: 3.2.8
| Groovy Version: 2.4.10
| JVM Version: 1.8.0_121
Run Code Online (Sandbox Code Playgroud)

所以它肯定是存在的..

grails intellij-idea

4
推荐指数
1
解决办法
6611
查看次数

类型错误:无法读取未定义的属性“client_secret”

我正在尝试按照 Google 的 Node API 在此处访问 gmail 。

将他们的示例快速入门作为 运行node quickstart.js时,出现以下错误:

TypeError: Cannot read property 'client_secret' of undefined
    at authorize (/home/user/example/quickstart.js:32:43)
    at processClientSecrets (/home/example/bstick/quickstart.js:21:3)
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:439:3)
Run Code Online (Sandbox Code Playgroud)
  • 我已经下载了密钥并对其进行了重命名client_secret.json,并将其复制到quickstart.js
  • node --version= 7.8.0, package.json 有"google-auth-library": "^0.10.0", "googleapis": "^19.0.0"

源代码(谷歌的例子):

var fs = require('fs');
var readline = require('readline');
var google = require('googleapis');
var googleAuth = require('google-auth-library');

// If modifying these scopes, delete your previously saved credentials
// at ~/.credentials/gmail-nodejs-quickstart.json
var SCOPES …
Run Code Online (Sandbox Code Playgroud)

javascript node.js gmail-api

4
推荐指数
2
解决办法
4077
查看次数

如何使用 Python 捕获 subprocess.call 错误?

我正在尝试下载特定的 Docker 映像,用户将在其中输入版本。但是,如果版本不存在,Docker 将抛出错误。

我正在使用subprocess.call管道从 Python 3 连接到终端。

示例代码:

from subprocess import call
containerName = input("Enter Docker container name: ")
swVersion = input("Enter software version: ")

call(["docker", "run", "--name", "{}".format(containerName), 
      "--detach", "--publish", "8080:8080", "user/software:{}".format(swVersion)])
Run Code Online (Sandbox Code Playgroud)

如果未找到版本,docker 将在终端中输出:

docker: Error response from daemon: manifest for user/software:8712378 not found.
Run Code Online (Sandbox Code Playgroud)

如何在 Python 脚本中捕获此错误?

类似的东西:

try:
    call(["docker", "run", "--name", "{}".format(containerName), "--detach", "--publish", "8080:8080", "user/software:{}".format(swVersion)])
except:
    # How do I catch the piped response code here?`
Run Code Online (Sandbox Code Playgroud)

python subprocess docker

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

从键值对中“过滤”出 JSON 对象的最有效方法是什么?

我正在阅读一个.json文件。它是一个有效 JSON 格式的对象数组,例如:

    [
        {
                "Id": 13,
                "Location": "Australia",
                "Content": "Another string"
        },
        {
                "Id": 145,
                "Location": "England",
                "Content": "SomeString"
        },
        {
                "Id": 12,
                "Location": "England",
                "Content": "SomeString"
        },
        {
                "Id": 12331,
                "Location": "Sweden",
                "Content": "SomeString"
        },
        {
                "Id": 213123,
                "Location": "England",
                "Content": "SomeString"
        }
     ]
Run Code Online (Sandbox Code Playgroud)

我想过滤掉这些对象 - 例如,删除任何"Location"不等于"England".

到目前为止我尝试过的是创建一个自定义UnmarshalJSON函数。它确实解组了它,但它产生的对象是空的 - 和输入一样多。

示例代码:

type languageStruct struct {
    ID                  int     `json:"Id"`
    Location            string  `json:"Location"` 
    Content             string  `json:"Content"`
}

func filterJSON(file []byte) ([]byte, error) …
Run Code Online (Sandbox Code Playgroud)

json go

4
推荐指数
1
解决办法
1602
查看次数

如何从远程获取最新的提交哈希?

无论分支如何,我都希望检索远程存储库上的最新提交哈希。

我已经尝试过git ls-remote <remote>git ls-remote --tags <remote>但是这两个似乎都是按标签名称排序的,这无法找出哪个是最新的。

例如,在 Github 上,您可以转到 Insights / Network 并获得一个图表,其中包含所有分支和提交——但是,在该 gui 中工作显然并不理想——但数据应该以某种方式存在。

有没有办法从远程获取最新的提交哈希而不管分支?

git

4
推荐指数
2
解决办法
4107
查看次数

React Native flexbox 如何垂直对齐项目?

我有点困惑为什么这个 flex 不起作用。

 <View
style={{
    display: "flex",
    flexWrap: "wrap"
}}
>
<View style={{ width: "40%", alignSelf: "flex-start" }}>
    <Button BUY</Button>
    <View style={{ alignSelf: "center", marginTop: "2%" }}>// A logo</View>
</View>
<View style={{ width: "40%", alignSelf: "flex-end" }}>
    <AreaChart
        style={{ height: 250 }}
        dataPoints={data}
        contentInset={{ top: 30, bottom: 30 }}
        curve={shape.curveNatural}
        svg={{
            fill: "rgba(134, 65, 244, 0.2)",
            stroke: "rgb(134, 65, 244)"
        }}
    />
</View>
</View>;
Run Code Online (Sandbox Code Playgroud)

我想要的预期布局是:

BUTTON  |   <CHART
LOGO    |   CHART>
Run Code Online (Sandbox Code Playgroud)

按钮和徽标一起居中,图表占据右侧的两个“框”。

但是,上述标记会产生以下结果:

BUTTON |
LOGO   |
       | CHART
       | …
Run Code Online (Sandbox Code Playgroud)

css flexbox react-native

3
推荐指数
1
解决办法
9143
查看次数

Docker-compose args 不会传递给 Dockerfile

我有一个docker-compose.yml文件,其中有一个给定服务的构建上下文,扩展名为Dockerfile.

示例 docker-compose:

version: '3'

services:

  scd-service:
    build:
      context: ./cmd/some-service/
      dockerfile: Dockerfile
      args:
        broker: redis:6379
        queue: somequeue
    depends_on:
      - redis
    networks:
      - backend

  redis:
    image: "redis:alpine"
    restart: unless-stopped
    networks:
      - backend
Run Code Online (Sandbox Code Playgroud)

它可以找到Dockerfile并构建它:docker-compose up --build some-service

但是,这将失败。在brokerqueueARG游戏从来没有通过给定的Dockerfile。

样品Dockerfile

FROM golang:1.11

// stuff...

ARG broker
ARG queue

CMD ["go", "run", "/go/src/github.com/org/project/cmd/some-service/some-service.go", "--broker $broker", "--queue $queue"]
Run Code Online (Sandbox Code Playgroud)

在构建阶段很明显,这些永远不会被解析:

Step 7/7 : CMD ["go", "run", "/go/src/github.com/org/project/cmd/some-service/some-service.go", "--broker $broker", "--queue $queue"]
Run Code Online (Sandbox Code Playgroud)

此后,由于命令行参数无效,Go 程序崩溃。 …

docker dockerfile docker-compose

3
推荐指数
1
解决办法
3726
查看次数