当前位置: 首页>>代码示例>>Golang>>正文


Golang DB.Debug方法代码示例

本文整理汇总了Golang中github.com/jinzhu/gorm.DB.Debug方法的典型用法代码示例。如果您正苦于以下问题:Golang DB.Debug方法的具体用法?Golang DB.Debug怎么用?Golang DB.Debug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/jinzhu/gorm.DB的用法示例。


在下文中一共展示了DB.Debug方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getAllUsers

func getAllUsers(db *gorm.DB) ([]MaillistUser, error) {
	var mus []MaillistUser
	err := db.Debug().Find(&mus).Error
	if err != nil {
		return nil, err
	}
	return mus, nil
}
开发者ID:jwmiller19,项目名称:revel-modz,代码行数:8,代码来源:maillist_user.go

示例2: DeleteTasks

func DeleteTasks(db *gorm.DB, ids []int64) error {
	item := new(models.Tasks)
	err := db.Debug().Where("id in (?)", ids).Delete(item).Error
	if err != nil {
		return err
	}
	return nil
}
开发者ID:rtm7777,项目名称:rozklad_cdtu,代码行数:8,代码来源:tasks.go

示例3: GetContacts

func GetContacts(db gorm.DB) {
	var contacts []Contact
	db.Debug().Table("Contacts").Find(&contacts)

	if len(contacts) <= 0 {
		fmt.Println("No records found!")
	} else {
		for _, contact := range contacts {
			fmt.Println(contact.SkypeName)
		}
	}
}
开发者ID:foysalit,项目名称:go-skype-analytics,代码行数:12,代码来源:main.go

示例4: main

func main() {
	// --------------------------------------------------------------------
	// Parse flags
	// --------------------------------------------------------------------
	var configFilePath string
	var printConfig bool
	var migrateDB bool
	var scheduler *remoteworkitem.Scheduler
	flag.StringVar(&configFilePath, "config", "", "Path to the config file to read")
	flag.BoolVar(&printConfig, "printConfig", false, "Prints the config (including merged environment variables) and exits")
	flag.BoolVar(&migrateDB, "migrateDatabase", false, "Migrates the database to the newest version and exits.")
	flag.Parse()

	// Override default -config switch with environment variable only if -config switch was
	// not explicitly given via the command line.
	configSwitchIsSet := false
	flag.Visit(func(f *flag.Flag) {
		if f.Name == "config" {
			configSwitchIsSet = true
		}
	})
	if !configSwitchIsSet {
		if envConfigPath, ok := os.LookupEnv("ALMIGHTY_CONFIG_FILE_PATH"); ok {
			configFilePath = envConfigPath
		}
	}

	var err error
	if err = configuration.Setup(configFilePath); err != nil {
		logrus.Panic(nil, map[string]interface{}{
			"configFilePath": configFilePath,
			"err":            err,
		}, "failed to setup the configuration")
	}

	if printConfig {
		os.Exit(0)
	}

	// Initialized developer mode flag for the logger
	log.InitializeLogger(configuration.IsPostgresDeveloperModeEnabled())

	printUserInfo()

	var db *gorm.DB
	for {
		db, err = gorm.Open("postgres", configuration.GetPostgresConfigString())
		if err != nil {
			db.Close()
			log.Logger().Errorf("ERROR: Unable to open connection to database %v\n", err)
			log.Logger().Infof("Retrying to connect in %v...\n", configuration.GetPostgresConnectionRetrySleep())
			time.Sleep(configuration.GetPostgresConnectionRetrySleep())
		} else {
			defer db.Close()
			break
		}
	}

	if configuration.IsPostgresDeveloperModeEnabled() {
		db = db.Debug()
	}

	// Migrate the schema
	err = migration.Migrate(db.DB())
	if err != nil {
		log.Panic(nil, map[string]interface{}{
			"err": fmt.Sprintf("%+v", err),
		}, "failed migration")
	}

	// Nothing to here except exit, since the migration is already performed.
	if migrateDB {
		os.Exit(0)
	}

	// Make sure the database is populated with the correct types (e.g. bug etc.)
	if configuration.GetPopulateCommonTypes() {
		// set a random request ID for the context
		ctx, req_id := client.ContextWithRequestID(context.Background())
		log.Debug(ctx, nil, "Initializing the population of the database... Request ID: %v", req_id)

		if err := models.Transactional(db, func(tx *gorm.DB) error {
			return migration.PopulateCommonTypes(ctx, tx, workitem.NewWorkItemTypeRepository(tx))
		}); err != nil {
			log.Panic(ctx, map[string]interface{}{
				"err": fmt.Sprintf("%+v", err),
			}, "failed to populate common types")
		}
		if err := models.Transactional(db, func(tx *gorm.DB) error {
			return migration.BootstrapWorkItemLinking(ctx, link.NewWorkItemLinkCategoryRepository(tx), link.NewWorkItemLinkTypeRepository(tx))
		}); err != nil {
			log.Panic(ctx, map[string]interface{}{
				"err": fmt.Sprintf("%+v", err),
			}, "failed to bootstap work item linking")
		}
	}

	// Scheduler to fetch and import remote tracker items
	scheduler = remoteworkitem.NewScheduler(db)
	defer scheduler.Stop()
//.........这里部分代码省略.........
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:101,代码来源:main.go

示例5: Insert

/*Point Insert to Sqlite*/
func (p Point) Insert(db gorm.DB) {
	if db.NewRecord(p) {
		db.Debug().Create(&p)
	}
}
开发者ID:highsoul,项目名称:zmy,代码行数:6,代码来源:point.go


注:本文中的github.com/jinzhu/gorm.DB.Debug方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。