<commit_before>// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.

package gdb_test

import (
	"fmt"
	"github.com/gogf/gf/container/garray"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/os/gcmd"

	"github.com/gogf/gf/database/gdb"
	"github.com/gogf/gf/os/gtime"
	"github.com/gogf/gf/test/gtest"
)

const (
	SIZE    = 10
	TABLE   = "user"
	SCHEMA1 = "test1"
	SCHEMA2 = "test2"
	PREFIX1 = "gf_"
)

var (
	db         gdb.DB
	dbPrefix   gdb.DB
	configNode gdb.ConfigNode
)

func init() {
	parser, err := gcmd.Parse(g.MapStrBool{
		"name": true,
		"type": true,
	}, false)
	gtest.Assert(err, nil)
	configNode = gdb.ConfigNode{
		Host:             "127.0.0.1",
		Port:             "3306",
		User:             "root",
		Pass:             "<PASSWORD>",
		Name:             parser.GetOpt("name", ""),
		Type:             parser.GetOpt("type", "mysql"),
		Role:             "master",
		Charset:          "utf8",
		Weight:           1,
		MaxIdleConnCount: 10,
		MaxOpenConnCount: 10,
		MaxConnLifetime:  600,
	}
	nodePrefix := configNode
	nodePrefix.Prefix = PREFIX1
	gdb.AddConfigNode("test", configNode)
	gdb.AddConfigNode("prefix", nodePrefix)
	gdb.AddConfigNode(gdb.DEFAULT_GROUP_NAME, configNode)
	// Default db.
	if r, err := gdb.New(); err != nil {
		gtest.Error(err)
	} else {
		db = r
	}
	db.SetDebug(true)
	schemaTemplate := "CREATE DATABASE IF NOT EXISTS `%s` CHARACTER SET UTF8"
	if _, err := db.Exec(fmt.Sprintf(schemaTemplate, SCHEMA1)); err != nil {
		gtest.Error(err)
	}
	if _, err := db.Exec(fmt.Sprintf(schemaTemplate, SCHEMA2)); err != nil {
		gtest.Error(err)
	}<commit_msg>add file rotation feature for package glog; improve gpool/gfpool; fix issue in gfile.MTimeMillisecond<commit_after>// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.

package gdb_test

import (
	"fmt"
	"github.com/gogf/gf/container/garray"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/os/gcmd"

	"github.com/gogf/gf/database/gdb"
	"github.com/gogf/gf/os/gtime"
	"github.com/gogf/gf/test/gtest"
)

const (
	SIZE    = 10
	TABLE   = "user"
	SCHEMA1 = "test1"
	SCHEMA2 = "test2"
	PREFIX1 = "gf_"
)

var (
	db         gdb.DB
	dbPrefix   gdb.DB
	configNode gdb.ConfigNode
)

func init() {
	parser, err := gcmd.Parse(g.MapStrBool{
		"name": true,
		"type": true,
	}, false)
	gtest.Assert(err, nil)
	configNode = gdb.ConfigNode{
		Host:             "127.0.0.1",
		Port:             "3306",
		User:             "root",
		Pass:             "<PASSWORD>",
		Name:             parser.GetOpt("name", ""),
		Type:             parser.GetOpt("type", "mysql"),
		Role:             "master",
		Charset:          "utf8",
		Weight:           1,
		MaxIdleConnCount: 10,
		MaxOpenConnCount: 10,
		MaxConnLifetime:  600,
	}
	nodePrefix := configNode
	nodePrefix.Prefix = PREFIX1
	gdb.AddConfigNode("test", configNode)
	gdb.AddConfigNode("prefix", nodePrefix)
	gdb.AddConfigNode(gdb.DEFAULT_GROUP_NAME, configNode)
	// Default db.
	if r, err := gdb.New(); err != nil {
		gtest.Error(err)
	} else {
		db = r
	}
	schemaTemplate := "CREATE DATABASE IF NOT EXISTS `%s` CHARACTER SET UTF8"
	if _, err := db.Exec(fmt.Sprintf(schemaTemplate, SCHEMA1)); err != nil {
		gtest.Error(err)
	}
	if _, err := db.Exec(fmt.Sprintf(schemaTemplate, SCHEMA2)); err != nil {
		gtest.Error(err)
	}
{'fraction_non_alphanumeric': 0.14799672935404742, 'fraction_numerical': 0.01853366039792859, 'mean_word_length': 2.8308977035490606, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6626551', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1417, 'n_words': 317}