github.com/zhongdalu/gf@v1.0.0/g/database/gdb/gdb_sqlite.go (about)

     1  // Copyright 2017 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/zhongdalu/gf.
     6  
     7  package gdb
     8  
     9  import (
    10  	"database/sql"
    11  )
    12  
    13  // 使用时需要import:
    14  // _ "github.com/zhongdalu/gf/third/github.com/mattn/go-sqlite3"
    15  
    16  // Sqlite接口对象
    17  // @author wxkj<wxscz@qq.com>
    18  
    19  // 数据库链接对象
    20  type dbSqlite struct {
    21  	*dbBase
    22  }
    23  
    24  func (db *dbSqlite) Open(config *ConfigNode) (*sql.DB, error) {
    25  	var source string
    26  	if config.LinkInfo != "" {
    27  		source = config.LinkInfo
    28  	} else {
    29  		source = config.Name
    30  	}
    31  	if db, err := sql.Open("sqlite3", source); err == nil {
    32  		return db, nil
    33  	} else {
    34  		return nil, err
    35  	}
    36  }
    37  
    38  // 获得关键字操作符
    39  func (db *dbSqlite) getChars() (charLeft string, charRight string) {
    40  	return "`", "`"
    41  }
    42  
    43  // 在执行sql之前对sql进行进一步处理。
    44  // @todo 需要增加对Save方法的支持,可使用正则来实现替换,
    45  // @todo 将ON DUPLICATE KEY UPDATE触发器修改为两条SQL语句(INSERT OR IGNORE & UPDATE)
    46  func (db *dbSqlite) handleSqlBeforeExec(query string) string {
    47  	return query
    48  }