小编kar*_*war的帖子

Golang sql 命名参数查询

我正在尝试在 golang 中使用命名参数查询,如下所示:

stmt, err := db.Prepare("insert into users(name, email) values(@name, @email)")
if err != nil {
    //error handling
}

res, err := stmt.Exec(sql.Named("name", name), sql.Named("email", email))

if err != nil {
        //error: sql: expected 0 arguments, got 2 
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:“sql:预期 0 个参数,得到 2 个”。

编写此查询的正确方法是什么?

mysql go

7
推荐指数
1
解决办法
9024
查看次数

聚合物示例代码在 Firefox 中不起作用

我正在尝试 Google 在https://www.polymer-project.org/1.0/start/first-element/intro提供的示例代码。

这是我到目前为止:

索引.html:

<!DOCTYPE html>                                                                                                          
<html lang="en">                                                                                                         
  <head>                                                                                                                 
    <meta charset="utf8">                                                                                                
    <meta http-equiv="X-UA-Compatible" content="IE=edge">                                                                
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">              
    <script src="https://polygit.org/components/webcomponentsjs/webcomponents-lite.js"></script>                         
    <link href="/my_components/icon-toggle-demo.html" rel="import">                                                      
  </head>                                                                                                                
  <body>                                                                                                                 
    <icon-toggle-demo toggle-icon="star"></icon-toggle-demo>                                                             
  </body>                                                                                                                
</html>  
Run Code Online (Sandbox Code Playgroud)

图标切换演示.html:

<link rel="import" href="https://polygit.org/components/polymer/polymer.html">                                              
<link rel="import" href="https://polygit.org/components/iron-icons/iron-icons.html">                                        
<link rel="import" href="icon-toggle.html">                                                                                 


<dom-module id="icon-toggle-demo">                                                                                          
  <template>                                                                                                                
    <style>                                                                                                                 
      :host {                                                                                                               
        font-family: sans-serif;                                                                                            
      };                                                                                                                    
    </style>                                                                                                                

    <h3>Statically-configured icon-toggles</h3>                                                                             

    <icon-toggle toggle-icon="star"></icon-toggle>                                                                          
    <icon-toggle toggle-icon="star" pressed></icon-toggle>                                                                  

    <h3>Data-bound icon-toggle</h3>                                                                                         

    <!-- use a computed binding to generate the message -->                                                                 
    <div><span>[[message(isFav)]]</span></div>                                                                              

    <!-- curly brackets ({{}}} allow two-way …
Run Code Online (Sandbox Code Playgroud)

polymer

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

Golang测试挂

我最近修改了我的应用程序,发现测试开始挂起。这是精简的测试代码:

package app_test                                                                    
                                                                                    
import (                                                                            
    "testing"                                                                   
    "github.com/kargirwar/prosql-go/db"                                         
)                                                                                   
                                                                                    
func TestApp(t *testing.T) {                                                        
    db.SetDbPath("")                                                            
}
Run Code Online (Sandbox Code Playgroud)

db包如下:

package db                                                                          
                                                                                    
import (                                                                            
        "os"                                                                        
        "context"                                                                   
        "database/sql"                                                              
        _ "github.com/mattn/go-sqlite3"                                             
        "path/filepath"                                                             
)                                                                                   
                                                                                    
var dbPath string                                                                   
                                                                                    
func SetDbPath(path string) {                                                       
        dbPath = path                                                               
}                                                                                   
                                                                                    
func OpenDb(ctx context.Context, db string) (*sql.DB, error) {                      
        db = filepath.Join(dbPath, db)                                              
                                                                                    
        _, err := os.OpenFile(db, os.O_RDWR, 0600)                                  
                                                                                    
        if err != nil {                                                             
                return nil, err                                                     
        }                                                                           
                                                                                    
        return sql.Open("sqlite3", "file:"+db+"?_foreign_keys=true")                
}  
Run Code Online (Sandbox Code Playgroud)

我将问题追溯到这种依赖关系:

_ "github.com/mattn/go-sqlite3" 
Run Code Online (Sandbox Code Playgroud)

如果我将其注释掉,那么测试就会正常运行,否则就会挂起。
奇怪的是, go run 工作得很好。Google 说 go-sqlite3 需要时间来编译,但是为什么 go …

go go-sqlite3

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

Vue.js道具观看无法正常工作

考虑以下简单的应用程序:

<div id="app">
  <counters :counter1="counter1" :counter2="counter2">
  </counters>
  <button @click="onClick">Click Here</button>
</div>
Run Code Online (Sandbox Code Playgroud)

JS:

Vue.component('counters', {
  template: '<h1>{{counter1.count}} {{counter2.count}}</h1>',
  //template: '<h1>{{count1}} {{count2}}</h1>',
  props: {
    'counter1': {
      type: Object
    },
    'counter2': {
      type: Object
    }
  },
  data: function() {
    return {
      'count1': 0,
      'count2': 0,
    }
  },
  watch: {
    counter1: function(n, o) {
      console.log(JSON.stringify(n));
      this.count1 = n.count;
    },
    counter2: function(n, o) {
      console.log(JSON.stringify(n));
      this.count2 = n.count;
    }
  }
});


var vm = new Vue({
  el: '#app',
  data: {
    counter1: {
      count: 0
    }, …
Run Code Online (Sandbox Code Playgroud)

vue.js

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

标签 统计

go ×2

go-sqlite3 ×1

mysql ×1

polymer ×1

vue.js ×1