go-on-rails 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd067bbca3b46eb5e2a99202de5051c0999cc9b1
4
- data.tar.gz: c512f1d35f70162b32ff9b072e8097e30558471f
3
+ metadata.gz: b708a7ebbdda649c91023ff597f4c2572bf2a3ca
4
+ data.tar.gz: 8ddb8f02f36a180b1a79c027e6ebbb5a53cc224f
5
5
  SHA512:
6
- metadata.gz: b0e8e5466e9b097c88c7c7507a28d95e80f120897ca7796858e2ddfbad4b7eac258cbcc9849d3d31e1bc0e750773bd4dba89f77ec55771b124e7bf0784265951
7
- data.tar.gz: '0946cdda0badf2dce152b99a933ccf46ce20d6f7f3e9db55e97b62c61b7e621af3cb10a0e5392374de7a7cb42618a8b554e3936f066f7157e6ca64a6f00c8315'
6
+ metadata.gz: 210ef6858d0c4ce898438a278ad82bea72eb4b8aad00bd7f093d082cc0eadaade36b40410af6d54b89b1e7f300024ae6b3835f08e821b79c2276f4299caa7cba
7
+ data.tar.gz: c8dc0b9bff1679124392a44223fa297a50ac586a15e6cc935ed6e3ed50b7b95cba352c523a0bf3fc898d2e6a0a697ba11307e87c855257c9828e23b606c37c04
data/README.md CHANGED
@@ -11,7 +11,7 @@ go-on-rails
11
11
  Add this line to your application's Gemfile:
12
12
 
13
13
  ```ruby
14
- gem 'go-on-rails'
14
+ gem 'go-on-rails', '~> 0.0.4'
15
15
  ```
16
16
 
17
17
  And then execute:
@@ -27,7 +27,7 @@ func Find<%= @model_name %>(id int64) (*<%= @model_name %>, error) {
27
27
  return nil, errors.New("Invalid id: it can't be zero")
28
28
  }
29
29
  var_<%= model_name_underscore %> := <%= @model_name %>{}
30
- err := db.Get(&var_<%= model_name_underscore %>, `SELECT * FROM <%= table_name %> WHERE id = ? LIMIT 1`, id)
30
+ err := db.Get(&var_<%= model_name_underscore %>, db.Rebind(`SELECT * FROM <%= table_name %> WHERE id = ? LIMIT 1`), id)
31
31
  if err != nil {
32
32
  log.Printf("Error: %v\n", err)
33
33
  return nil, err
@@ -44,7 +44,7 @@ func Find<%= @model_name.pluralize %>(ids ...int64) ([]<%= @model_name %>, error
44
44
  }
45
45
  var_<%= param_name_plural %> := []<%= @model_name %>{}
46
46
  idsHolder := strings.Repeat(",?", len(ids)-1)
47
- sql := fmt.Sprintf(`SELECT * FROM <%= table_name %> WHERE id IN (?%s)`, idsHolder)
47
+ sql := db.Rebind(fmt.Sprintf(`SELECT * FROM <%= table_name %> WHERE id IN (?%s)`, idsHolder))
48
48
  idsT := []interface{}{}
49
49
  for _,id := range ids {
50
50
  idsT = append(idsT, interface{}(id))
@@ -62,7 +62,7 @@ func Find<%= @model_name %>By(field string, val interface{}) (*<%= @model_name %
62
62
  var_<%= model_name_underscore %> := <%= @model_name %>{}
63
63
  sqlFmt := `SELECT * FROM <%= table_name %> WHERE %s = ? LIMIT 1`
64
64
  sqlStr := fmt.Sprintf(sqlFmt, field)
65
- err := db.Get(&var_<%= model_name_underscore %>, sqlStr, val)
65
+ err := db.Get(&var_<%= model_name_underscore %>, db.Rebind(sqlStr), val)
66
66
  if err != nil {
67
67
  log.Printf("Error: %v\n", err)
68
68
  return nil, err
@@ -74,7 +74,7 @@ func Find<%= @model_name %>By(field string, val interface{}) (*<%= @model_name %
74
74
  func Find<%= @model_name.pluralize %>By(field string, val interface{}) (var_<%= param_name_plural %> []<%= @model_name %>, err error) {
75
75
  sqlFmt := `SELECT * FROM <%= table_name %> WHERE %s = ?`
76
76
  sqlStr := fmt.Sprintf(sqlFmt, field)
77
- err = db.Select(&var_<%= param_name_plural %>, sqlStr, val)
77
+ err = db.Select(&var_<%= param_name_plural %>, db.Rebind(sqlStr), val)
78
78
  if err != nil {
79
79
  log.Printf("Error: %v\n", err)
80
80
  return nil, err
@@ -196,7 +196,7 @@ func <%= @model_name %>IntCol(col, where string, args ...interface{}) (intColRec
196
196
  if len(where) > 0 {
197
197
  sql = sql + " WHERE " + where
198
198
  }
199
- stmt, err := db.Preparex(sql)
199
+ stmt, err := db.Preparex(db.Rebind(sql))
200
200
  if err != nil {
201
201
  log.Println(err)
202
202
  return nil, err
@@ -215,7 +215,7 @@ func <%= @model_name %>StrCol(col, where string, args ...interface{}) (strColRec
215
215
  if len(where) > 0 {
216
216
  sql = sql + " WHERE " + where
217
217
  }
218
- stmt, err := db.Preparex(sql)
218
+ stmt, err := db.Preparex(db.Rebind(sql))
219
219
  if err != nil {
220
220
  log.Println(err)
221
221
  return nil, err
@@ -236,7 +236,7 @@ func Find<%= @model_name.pluralize %>Where(where string, args ...interface{}) (<
236
236
  if len(where) > 0 {
237
237
  sql = sql + " WHERE " + where
238
238
  }
239
- stmt, err := db.Preparex(sql)
239
+ stmt, err := db.Preparex(db.Rebind(sql))
240
240
  if err != nil {
241
241
  log.Println(err)
242
242
  return nil, err
@@ -253,7 +253,7 @@ func Find<%= @model_name.pluralize %>Where(where string, args ...interface{}) (<
253
253
  // with placeholders, eg: FindUsersBySql("SELECT * FROM users WHERE first_name = ? AND age > ?", "John", 18)
254
254
  // will return those records in the table "users" whose first_name is "John" and age elder than 18
255
255
  func Find<%= @model_name.pluralize %>BySql(sql string, args ...interface{}) (<%= param_name_plural %> []<%= @model_name %>, err error) {
256
- stmt, err := db.Preparex(sql)
256
+ stmt, err := db.Preparex(db.Rebind(sql))
257
257
  if err != nil {
258
258
  log.Println(err)
259
259
  return nil, err
@@ -395,7 +395,7 @@ func (var_<%= model_name_underscore %> *<%= @model_name %>) Destroy() error {
395
395
  }
396
396
 
397
397
  func Destroy<%= @model_name %>(id int64) error {
398
- stmt, err := db.Preparex(`DELETE FROM <%= table_name %> WHERE id = ?`)
398
+ stmt, err := db.Preparex(db.Rebind(`DELETE FROM <%= table_name %> WHERE id = ?`))
399
399
  _, err = stmt.Exec(id)
400
400
  if err != nil {
401
401
  return err
@@ -449,7 +449,7 @@ func Destroy<%= @model_name.pluralize %>(ids ...int64) (int64, error) {
449
449
  for _,id := range ids {
450
450
  idsT = append(idsT, interface{}(id))
451
451
  }
452
- stmt, err := db.Preparex(sql)
452
+ stmt, err := db.Preparex(db.Rebind(sql))
453
453
  result, err := stmt.Exec(idsT...)
454
454
  if err != nil {
455
455
  return 0, err
@@ -487,7 +487,7 @@ func Destroy<%= @model_name.pluralize %>Where(where string, args ...interface{})
487
487
  } else {
488
488
  return 0, errors.New("No WHERE conditions provided")
489
489
  }
490
- stmt, err := db.Preparex(sql)
490
+ stmt, err := db.Preparex(db.Rebind(sql))
491
491
  result, err := stmt.Exec(args...)
492
492
  if err != nil {
493
493
  return 0, err
@@ -573,7 +573,7 @@ func Update<%= @model_name.pluralize %>BySql(sql string, args ...interface{}) (i
573
573
  sql = strings.Replace(strings.ToLower(sql), "set", "set updated_at = ?, ", 1)
574
574
  args = append([]interface{}{time.Now()}, args...)
575
575
  <%- end -%>
576
- stmt, err := db.Preparex(sql)
576
+ stmt, err := db.Preparex(db.Rebind(sql))
577
577
  result, err := stmt.Exec(args...)
578
578
  if err != nil {
579
579
  return 0, err
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: go-on-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - B1nj0y