@ -10,11 +10,11 @@ Grafana supports the [following databases](https://grafana.com/docs/installation
Grafana uses the [XORM](https://xorm.io) framework for persisting objects to the database. For more information on how to use XORM, refer to the [documentation](http://gobook.io/read/github.com/go-xorm/manual-en-US/).
[Services](services.md) don't use XORM directly. Instead, services use the _SQL store_, a special type of service that provides an abstraction for the database layer. There are two ways of using the `sqlstore`: using `sqlstore` handlers, and using the `SqlStore` instance.
[Services](services.md) don't use XORM directly. Instead, services use the _SQL store_, a special type of service that provides an abstraction for the database layer. There are two ways of using the `sqlstore`: using `sqlstore` handlers, and using the `SQLStore` instance.
## `sqlstore` handlers
> **Deprecated:** We are deprecating `sqlstore` handlers in favor of using the `SqlStore` object directly in each service. Since most services still use the `sqlstore` handlers, we still want to explain how they work.
> **Deprecated:** We are deprecating `sqlstore` handlers in favor of using the `SQLStore` object directly in each service. Since most services still use the `sqlstore` handlers, we still want to explain how they work.
The `sqlstore` package allows you to register [command handlers](communication.md#handle-commands) that either store, or retrieve objects from the database. `sqlstore` handlers are similar to services:
Here, `inTransaction` is a helper function in the `sqlstore` package that provides a session, that lets you execute SQL statements.
## `SqlStore`
## `SQLStore`
As opposed to a `sqlstore` handler, the `SqlStore` is a service itself. The `SqlStore` has the same responsibility however: to store and retrieve objects, to and from the database.
As opposed to a `sqlstore` handler, the `SQLStore` is a service itself. The `SQLStore` has the same responsibility however: to store and retrieve objects, to and from the database.
To use the `SqlStore`, inject the `SQLStore` in your service struct:
To use the `SQLStore`, inject it in your service struct:
varrawSql=`SELECT uid, slug from dashboard WHERE Id=?`
varrawSQL=`SELECT uid, slug from dashboard WHERE Id=?`
us:=&models.DashboardRef{}
exists,err:=x.SQL(rawSql,query.Id).Get(us)
exists,err:=x.SQL(rawSQL,query.Id).Get(us)
iferr!=nil{
returnerr
@ -710,7 +710,7 @@ func HasEditPermissionInFolders(query *models.HasEditPermissionInFoldersQuery) e
returnnil
}
builder:=&SqlBuilder{}
builder:=&SQLBuilder{}
builder.Write("SELECT COUNT(dashboard.id) AS count FROM dashboard WHERE dashboard.org_id = ? AND dashboard.is_folder = ?",query.SignedInUser.OrgId,dialect.BooleanStr(true))
builder.Write("SELECT COUNT(dashboard.id) AS count FROM dashboard WHERE dashboard.org_id = ? AND dashboard.is_folder = ?",query.SignedInUser.OrgId,dialect.BooleanStr(true))
sql:="SELECT 1 FROM "+db.Quote("INFORMATION_SCHEMA")+"."+db.Quote("STATISTICS")+" WHERE "+db.Quote("TABLE_SCHEMA")+" = DATABASE() AND "+db.Quote("TABLE_NAME")+"=? AND "+db.Quote("INDEX_NAME")+"=?"
sql:="SELECT 1 FROM "+db.Quote("INFORMATION_SCHEMA")+"."+db.Quote("COLUMNS")+" WHERE "+db.Quote("TABLE_SCHEMA")+" = DATABASE() AND "+db.Quote("TABLE_NAME")+"=? AND "+db.Quote("COLUMN_NAME")+"=?"
builder.Write("SELECT COUNT(team.id) AS count FROM team INNER JOIN team_member ON team_member.team_id = team.id WHERE team.org_id = ? AND team_member.user_id = ? AND team_member.permission = ?",query.SignedInUser.OrgId,query.SignedInUser.UserId,models.PERMISSION_ADMIN)