Tqla是一种轻巧的小型文本解析器,可包裹golang text/template
标准库。tqla的主要目的是解析文本模板,并用占位符替换任何变量。用占位符替换的变量将添加到可以传递给标准db驱动程序的args切片中。
类似的库也暴露于sql注入,因为它们使用文本/模板库进行简单的文本替换。Tqla通过如上所述利用DB占位符来防止sql注入 这里.
当前,tqla不会尝试进行任何sql验证,将来可能会更改。
以下是有关如何使用它的简单示例:
package main
import (
"database/sql"
"log"
"github.com/VauntDev/tqla"
_ "github.com/mattn/go-sqlite3"
)
type todo struct {
Id int
Title string
Description string
Completed bool
}
const db = "example.db"
const todoSchema = `create table if not exists todos (
id integer primary key,
title text not null,
description text not null,
completed boolean default 0
);
`
func main() {
log.Println("connecting to db... ")
db, err := sql.Open("sqlite3", db)
if err !&#