(typ string, addr string, options graph.Options)
| 212 | } |
| 213 | |
| 214 | func Init(typ string, addr string, options graph.Options) error { |
| 215 | if typ == "" { |
| 216 | typ = typeFromOpts(options) |
| 217 | } |
| 218 | fl, ok := types[typ] |
| 219 | if !ok { |
| 220 | return fmt.Errorf("unsupported sql database: %s", typ) |
| 221 | } |
| 222 | conn, err := connect(addr, fl.Driver, options) |
| 223 | if err != nil { |
| 224 | return err |
| 225 | } |
| 226 | defer conn.Close() |
| 227 | |
| 228 | nodesSql := fl.nodesTable() |
| 229 | quadsSql := fl.quadsTable() |
| 230 | indexes := fl.quadIndexes(options) |
| 231 | |
| 232 | if fl.NoSchemaChangesInTx { |
| 233 | _, err = conn.Exec(nodesSql) |
| 234 | if err != nil { |
| 235 | err = fl.Error(err) |
| 236 | clog.Errorf("Cannot create nodes table: %v", err) |
| 237 | return err |
| 238 | } |
| 239 | _, err = conn.Exec(quadsSql) |
| 240 | if err != nil { |
| 241 | err = fl.Error(err) |
| 242 | clog.Errorf("Cannot create quad table: %v", err) |
| 243 | return err |
| 244 | } |
| 245 | for _, index := range indexes { |
| 246 | if _, err = conn.Exec(index); err != nil { |
| 247 | clog.Errorf("Cannot create index: %v", err) |
| 248 | return err |
| 249 | } |
| 250 | } |
| 251 | } else { |
| 252 | tx, err := conn.Begin() |
| 253 | if err != nil { |
| 254 | clog.Errorf("Couldn't begin creation transaction: %s", err) |
| 255 | return err |
| 256 | } |
| 257 | |
| 258 | _, err = tx.Exec(nodesSql) |
| 259 | if err != nil { |
| 260 | tx.Rollback() |
| 261 | err = fl.Error(err) |
| 262 | clog.Errorf("Cannot create nodes table: %v", err) |
| 263 | return err |
| 264 | } |
| 265 | _, err = tx.Exec(quadsSql) |
| 266 | if err != nil { |
| 267 | tx.Rollback() |
| 268 | err = fl.Error(err) |
| 269 | clog.Errorf("Cannot create quad table: %v", err) |
| 270 | return err |
| 271 | } |
no test coverage detected