github.com/abayer/test-infra@v0.0.5/velodrome/sql/testing/sqlite.go (about)

     1  /*
     2  Copyright 2016 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package testing
    18  
    19  import (
    20  	"k8s.io/test-infra/velodrome/sql"
    21  
    22  	"github.com/jinzhu/gorm"
    23  	// SQLite needs to be initialized if you use this module
    24  	_ "github.com/jinzhu/gorm/dialects/sqlite"
    25  )
    26  
    27  // SQLiteConfig helps you create a SQLite database
    28  type SQLiteConfig struct {
    29  	File string
    30  }
    31  
    32  // CreateDatabase the SQLite DB
    33  func (config *SQLiteConfig) CreateDatabase() (*gorm.DB, error) {
    34  	db, err := gorm.Open("sqlite3", config.File)
    35  	if err != nil {
    36  		return nil, err
    37  	}
    38  
    39  	err = db.AutoMigrate(&sql.Assignee{}, &sql.Issue{}, &sql.IssueEvent{}, &sql.Label{}, &sql.Comment{}).Error
    40  	if err != nil {
    41  		return nil, err
    42  	}
    43  
    44  	return db, nil
    45  }