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


Golang db.InitDBWithSchemas函数代码示例

本文整理汇总了Golang中github.com/cloudwan/gohan/db.InitDBWithSchemas函数的典型用法代码示例。如果您正苦于以下问题:Golang InitDBWithSchemas函数的具体用法?Golang InitDBWithSchemas怎么用?Golang InitDBWithSchemas使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: InitializeEnvironment

// InitializeEnvironment creates new transaction for the test
func (env *Environment) InitializeEnvironment() error {
	var err error
	_, file := filepath.Split(env.testFileName)
	env.dbFile, err = ioutil.TempFile(os.TempDir(), file)
	if err != nil {
		return fmt.Errorf("Failed to create a temporary file in %s: %s", os.TempDir(), err.Error())
	}
	env.dbConnection, err = newDBConnection(env.dbFile.Name())
	if err != nil {
		return fmt.Errorf("Failed to connect to database: %s", err.Error())
	}
	env.Environment = gohan_otto.NewEnvironment(env.dbConnection, &middleware.FakeIdentity{}, 30*time.Second)
	env.SetUp()
	env.addTestingAPI()

	script, err := env.VM.Compile(env.testFileName, env.testSource)
	if err != nil {
		return fmt.Errorf("Failed to compile the file '%s': %s", env.testFileName, err.Error())
	}

	env.VM.Run(script)
	err = env.loadSchemas()
	if err != nil {
		schema.ClearManager()
		return fmt.Errorf("Failed to load schema for '%s': %s", env.testFileName, err.Error())
	}

	err = db.InitDBWithSchemas("sqlite3", env.dbFile.Name(), true, false)
	if err != nil {
		schema.ClearManager()
		return fmt.Errorf("Failed to init DB: %s", err.Error())
	}

	return nil
}
开发者ID:masaki-saeki,项目名称:gohan,代码行数:36,代码来源:environment.go

示例2: getInitDbCommand

func getInitDbCommand() cli.Command {
	return cli.Command{
		Name:      "init-db",
		ShortName: "idb",
		Usage:     "Initialize DB backend with given schema file",
		Description: `
Initialize empty database with given schema.

Setting meta-schema option will additionaly populate meta-schema table with schema resources.
Useful for development purposes.`,
		Flags: []cli.Flag{
			cli.StringFlag{Name: "database-type, t", Value: "sqlite3", Usage: "Backend datebase type"},
			cli.StringFlag{Name: "database, d", Value: "gohan.db", Usage: "DB connection string"},
			cli.StringFlag{Name: "schema, s", Value: "etc/schema/gohan.json", Usage: "Schema definition"},
			cli.BoolFlag{Name: "drop-on-create", Usage: "If true, old database will be dropped"},
			cli.BoolFlag{Name: "cascade", Usage: "If true, FOREIGN KEYS in database will be created with ON DELETE CASCADE"},
			cli.StringFlag{Name: "meta-schema, m", Value: "", Usage: "Meta-schema file (optional)"},
		},
		Action: func(c *cli.Context) {
			dbType := c.String("database-type")
			dbConnection := c.String("database")
			schemaFile := c.String("schema")
			metaSchemaFile := c.String("meta-schema")
			dropOnCreate := c.Bool("drop-on-create")
			cascade := c.Bool("cascade")
			manager := schema.GetManager()
			manager.LoadSchemasFromFiles(schemaFile, metaSchemaFile)
			err := db.InitDBWithSchemas(dbType, dbConnection, dropOnCreate, cascade)
			if err != nil {
				util.ExitFatal(err)
			}
			fmt.Println("DB is initialized")
		},
	}
}
开发者ID:masaki-saeki,项目名称:gohan,代码行数:35,代码来源:cli.go

示例3: initBenchmarkDatabase

func initBenchmarkDatabase() error {
	schema.ClearManager()
	manager := schema.GetManager()
	manager.LoadSchemasFromFiles("../etc/apps/example.yaml", "../etc/schema/gohan.json")
	err := db.InitDBWithSchemas("mysql", "[email protected](localhost:3306)/gohan_test", false, false)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:gitter-badger,项目名称:gohan,代码行数:10,代码来源:server_test.go

示例4: TestOttoExtension

		}
	}
	return nil
}

func TestOttoExtension(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Otto Extension Suite")
}

var _ = Describe("Suite set up and tear down", func() {
	var _ = BeforeSuite(func() {
		var err error
		Expect(os.Chdir(configDir)).To(Succeed())
		testDB, err = db.ConnectDB(dbType, dbFile, db.DefaultMaxOpenConn)
		Expect(err).ToNot(HaveOccurred(), "Failed to connect database.")
		manager := schema.GetManager()
		config := util.GetConfig()
		Expect(config.ReadConfig(configFile)).To(Succeed())
		schemaFiles := config.GetStringList("schemas", nil)
		Expect(schemaFiles).NotTo(BeNil())
		Expect(manager.LoadSchemasFromFiles(schemaFiles...)).To(Succeed())
		Expect(db.InitDBWithSchemas(dbType, dbFile, false, false)).To(Succeed())
	})

	var _ = AfterSuite(func() {
		schema.ClearManager()
		os.Remove(dbFile)
	})
})
开发者ID:marcin-ptaszynski,项目名称:gohan,代码行数:30,代码来源:otto_suite_test.go

示例5:

		var dbType string
		if os.Getenv("MYSQL_TEST") == "true" {
			conn = "gohan:[email protected]/gohan_test"
			dbType = "mysql"
		} else {
			conn = "./test.db"
			dbType = "sqlite3"
		}

		manager := schema.GetManager()
		dbc, err := db.ConnectDB(dbType, conn, db.DefaultMaxOpenConn)
		sqlConn = dbc.(*DB)
		Expect(err).ToNot(HaveOccurred())
		Expect(manager.LoadSchemasFromFiles(
			"../../etc/schema/gohan.json", "../../tests/test_abstract_schema.yaml", "../../tests/test_schema.yaml")).To(Succeed())
		db.InitDBWithSchemas(dbType, conn, true, false)

		// Insert fixture data
		fixtureDB, err := db.ConnectDB("json", "test_fixture.json", db.DefaultMaxOpenConn)
		Expect(err).ToNot(HaveOccurred())
		db.CopyDBResources(fixtureDB, dbc, true)

		tx, err = dbc.Begin()
		Expect(err).ToNot(HaveOccurred())
	})

	AfterEach(func() {
		schema.ClearManager()
		if os.Getenv("MYSQL_TEST") != "true" {
			os.Remove(conn)
		}
开发者ID:cloudwan,项目名称:gohan,代码行数:31,代码来源:sql_test.go

示例6:

					})
				})
			})
		})
	})

	Context("Initialization", func() {
		BeforeEach(func() {
			conn = "test.db"
			dbType = "sqlite3"
			Expect(manager.LoadSchemaFromFile("../tests/test_abstract_schema.yaml")).To(Succeed())
			Expect(manager.LoadSchemaFromFile("../tests/test_schema.yaml")).To(Succeed())
		})

		It("Should initialize the database without error", func() {
			Expect(db.InitDBWithSchemas(dbType, conn, false, false)).To(Succeed())
		})
	})

	Context("Converting", func() {
		BeforeEach(func() {
			Expect(manager.LoadSchemaFromFile("test_data/conv_in.yaml")).To(Succeed())
		})

		It("Should do it properly", func() {
			inDB, err := db.ConnectDB("yaml", "test_data/conv_in.yaml", db.DefaultMaxOpenConn)
			Expect(err).ToNot(HaveOccurred())
			defer os.Remove("test_data/conv_in.db")

			db.InitDBWithSchemas("sqlite3", "test_data/conv_out.db", false, false)
			outDB, err := db.ConnectDB("sqlite3", "test_data/conv_out.db", db.DefaultMaxOpenConn)
开发者ID:vozhyk-,项目名称:gohan,代码行数:31,代码来源:db_test.go

示例7: initDB

func (server *Server) initDB() error {
	return db.InitDBWithSchemas(server.getDatabaseConfig())
}
开发者ID:gitter-badger,项目名称:gohan,代码行数:3,代码来源:server.go

示例8: InitDB

//InitDB initializes database using schema.
func InitDB(dbType string, connection string, dropOnCreate bool, cascade bool) error {
	err := db.InitDBWithSchemas(dbType, connection, dropOnCreate, cascade)
	return err
}
开发者ID:marcin-ptaszynski,项目名称:gohan,代码行数:5,代码来源:gohan.go


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