package apigen

import "git.qianqiusoft.com/qianqiusoft/light-apiengine-client/code_gen/utils"

const sqlTmpl = `
<sqlMap>
    <sql id="insert_{{.data.Name}}">
        INSERT INTO {{.data.Name}}
		({{SqlAllColumns .data.ColumnList false}})
		VALUES
		({{SqlAllColumns .data.ColumnList true}})
    </sql>
    <sql id="update_{{.data.Name}}">
        UPDATE {{.data.Name}} SET
		{{SqlNoPKUpdate .data.ColumnList}}
		WHERE {{SqlPKWhere .data.ColumnList}}
    </sql>
    <sql id="deleteone_{{.data.Name}}">
        DELETE FROM {{.data.Name}}
		WHERE {{SqlPKWhere .data.ColumnList}}
    </sql>
    <sql id="selectone_{{.data.Name}}">
        SELECT
			{{SqlAllColumns .data.ColumnList false}}
        FROM {{.data.Name}}
		WHERE {{SqlPKWhere .data.ColumnList}}
    </sql>
    <sql id="selectall_{{.data.Name}}">
        SELECT
			{{SqlAllColumns .data.ColumnList false}}
        FROM {{.data.Name}}
    </sql>
</sqlMap>
`

func GenSql(templateData interface{}, params map[string]interface{}) ([]byte, error) {
	return utils.GenTemplate(sqlTmpl, templateData, params)
}
