回答編集履歴

5

add

2017/09/14 04:34

投稿

mattn
mattn

スコア5030

test CHANGED
@@ -217,3 +217,67 @@
217
217
  ```
218
218
 
219
219
 
220
+
221
+ #追記2について
222
+
223
+
224
+
225
+ 以下のコードで test.sqlite3 にレコードが追加されている(foo/barも入っている)事は確認出来ています。
226
+
227
+ DB Browser for SQLite のリロードボタンなどで最新が表示されないでしょうか。
228
+
229
+
230
+
231
+ ```go
232
+
233
+ package main
234
+
235
+
236
+
237
+ import (
238
+
239
+ "github.com/jinzhu/gorm"
240
+
241
+ _ "github.com/jinzhu/gorm/dialects/sqlite"
242
+
243
+ )
244
+
245
+
246
+
247
+ type UserData struct {
248
+
249
+ gorm.Model
250
+
251
+ Userid string
252
+
253
+ Password string
254
+
255
+ }
256
+
257
+
258
+
259
+ func main() {
260
+
261
+ db, err := gorm.Open("sqlite3", "test.sqlite3")
262
+
263
+ if err != nil {
264
+
265
+ panic("failed to connect database: " + err.Error())
266
+
267
+ }
268
+
269
+ defer db.Close()
270
+
271
+ // Migrate the schema
272
+
273
+ db.AutoMigrate(&UserData{})
274
+
275
+ // Create
276
+
277
+ user := &UserData{Userid: "foo", Password: "bar"}
278
+
279
+ db.Create(&user)
280
+
281
+ }
282
+
283
+ ```

4

fix

2017/09/14 04:34

投稿

mattn
mattn

スコア5030

test CHANGED
@@ -70,7 +70,7 @@
70
70
 
71
71
 
72
72
 
73
- この形式は、`gorm.Model` を内包する形式です。こう書く事で実際は以下の struct メンバも内される事になります。
73
+ この形式は、`gorm.Model` を内包する形式です。こう書く事で実際は以下の struct メンバも内される事になります。
74
74
 
75
75
 
76
76
 

3

fix

2017/09/11 10:57

投稿

mattn
mattn

スコア5030

test CHANGED
@@ -112,6 +112,8 @@
112
112
 
113
113
 
114
114
 
115
+ なお、gorm 等の様に ORM を使う場合、Create Table すらも ORM に任せるのが一般的ですが、テーブルのフィールドに `gorm:` のプレフィックスタグを付ける事で既存の DDL を使ったテーブル操作も出来ます。
116
+
115
117
 
116
118
 
117
119
  ## 検索

2

fix

2017/09/11 00:53

投稿

mattn
mattn

スコア5030

test CHANGED
@@ -195,3 +195,23 @@
195
195
 
196
196
 
197
197
  [https://github.com/jinzhu/gorm/blob/master/dialects/postgres/postgres.go](https://github.com/jinzhu/gorm/blob/master/dialects/postgres/postgres.go)
198
+
199
+
200
+
201
+ sqlite3 だけでなく他のデータベースにもつなげたいならば、使う分 import する必要があります。
202
+
203
+
204
+
205
+ ```go
206
+
207
+ import _ "github.com/jinzhu/gorm/dialects/mysql"
208
+
209
+ // import _ "github.com/jinzhu/gorm/dialects/postgres"
210
+
211
+ // import _ "github.com/jinzhu/gorm/dialects/sqlite"
212
+
213
+ // import _ "github.com/jinzhu/gorm/dialects/mssql"
214
+
215
+ ```
216
+
217
+

1

fix

2017/09/11 00:19

投稿

mattn
mattn

スコア5030

test CHANGED
@@ -44,7 +44,7 @@
44
44
 
45
45
 
46
46
 
47
- https://sqlite.org/uri.html
47
+ [https://sqlite.org/uri.html](https://sqlite.org/uri.html)
48
48
 
49
49
 
50
50