2022-01-24 14:47:22 +08:00
# drivers
2024-04-15 10:03:49 +08:00
2022-05-13 21:54:24 +08:00
Powerful database drivers for package gdb.
2022-01-24 14:41:23 +08:00
# Installation
2024-04-15 10:03:49 +08:00
2022-05-13 21:54:24 +08:00
Let's take `mysql` for example.
2024-04-15 10:03:49 +08:00
```shell
2022-05-13 21:54:24 +08:00
go get -u github.com/gogf/gf/contrib/drivers/mysql/v2
2024-04-15 10:03:49 +08:00
# Easy to copy
go get -u github.com/gogf/gf/contrib/drivers/clickhouse/v2
go get -u github.com/gogf/gf/contrib/drivers/dm/v2
go get -u github.com/gogf/gf/contrib/drivers/mssql/v2
go get -u github.com/gogf/gf/contrib/drivers/oracle/v2
go get -u github.com/gogf/gf/contrib/drivers/pgsql/v2
go get -u github.com/gogf/gf/contrib/drivers/sqlite/v2
go get -u github.com/gogf/gf/contrib/drivers/sqlitecgo/v2
2022-01-24 14:41:23 +08:00
```
Choose and import the driver to your project:
2024-04-15 10:03:49 +08:00
```go
2022-05-13 21:54:24 +08:00
import _ "github.com/gogf/gf/contrib/drivers/mysql/v2"
```
Commonly imported at top of `main.go`:
2024-04-15 10:03:49 +08:00
2022-05-13 21:54:24 +08:00
```go
package main
import (
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
// Other imported packages.
)
func main() {
// Main logics.
}
2022-01-24 14:41:23 +08:00
```
# Supported Drivers
2022-04-12 21:31:51 +08:00
## MySQL/MariaDB/TiDB
2022-01-24 14:41:23 +08:00
2024-04-15 10:03:49 +08:00
```go
2022-04-15 14:47:02 +08:00
import _ "github.com/gogf/gf/contrib/drivers/mysql/v2"
```
2022-01-24 14:41:23 +08:00
## SQLite
2024-04-15 10:03:49 +08:00
```go
2022-01-27 12:04:46 +08:00
import _ "github.com/gogf/gf/contrib/drivers/sqlite/v2"
2022-01-24 14:41:23 +08:00
```
2024-04-15 10:03:49 +08:00
### cgo version for 32-bit windows
```go
import _ "github.com/gogf/gf/contrib/drivers/sqlitecgo/v2"
2022-01-24 14:41:23 +08:00
```
2024-04-15 10:03:49 +08:00
## PostgreSQL
```go
2022-01-27 12:04:46 +08:00
import _ "github.com/gogf/gf/contrib/drivers/pgsql/v2"
2022-01-24 14:41:23 +08:00
```
2024-04-15 10:03:49 +08:00
2022-01-24 14:41:23 +08:00
Note:
2024-04-15 10:03:49 +08:00
2024-03-07 11:34:49 +08:00
- It does not support `Replace` features.
2022-01-24 14:41:23 +08:00
## SQL Server
2024-04-15 10:03:49 +08:00
```go
2022-01-27 12:04:46 +08:00
import _ "github.com/gogf/gf/contrib/drivers/mssql/v2"
2022-01-24 14:41:23 +08:00
```
2024-04-15 10:03:49 +08:00
2022-01-24 14:41:23 +08:00
Note:
2024-04-15 10:03:49 +08:00
2024-04-01 19:18:54 +08:00
- It does not support `Replace` features.
2022-01-24 14:41:23 +08:00
- It does not support `LastInsertId`.
- It supports server version >= `SQL Server2005`
2024-04-15 10:03:49 +08:00
- It ONLY supports datetime2 and datetimeoffset types for auto handling created_at/updated_at/deleted_at columns, because datetime type does not support microseconds precision when column value is passed as string.
2022-01-24 14:41:23 +08:00
## Oracle
2024-04-15 10:03:49 +08:00
```go
2022-01-27 12:04:46 +08:00
import _ "github.com/gogf/gf/contrib/drivers/oracle/v2"
2022-01-24 14:41:23 +08:00
```
2024-04-15 10:03:49 +08:00
2022-01-24 14:41:23 +08:00
Note:
2024-04-15 10:03:49 +08:00
2024-04-01 19:18:54 +08:00
- It does not support `Replace` features.
2022-01-24 14:41:23 +08:00
- It does not support `LastInsertId`.
2022-04-12 21:31:51 +08:00
## ClickHouse
2024-04-15 10:03:49 +08:00
```go
2022-04-12 21:31:51 +08:00
import _ "github.com/gogf/gf/contrib/drivers/clickhouse/v2"
```
2024-04-15 10:03:49 +08:00
2022-04-12 21:31:51 +08:00
Note:
2024-04-15 10:03:49 +08:00
2022-04-12 21:31:51 +08:00
- It does not support `InsertIgnore/InsertGetId` features.
- It does not support `Save/Replace` features.
- It does not support `Transaction` feature.
2022-05-23 21:21:59 +08:00
- It does not support `RowsAffected` feature.
2022-04-12 21:31:51 +08:00
2022-09-26 22:11:13 +08:00
## DM
2024-04-15 10:03:49 +08:00
```go
2022-09-26 22:11:13 +08:00
import _ "github.com/gogf/gf/contrib/drivers/dm/v2"
```
2022-10-09 21:23:55 +08:00
2024-04-15 10:03:49 +08:00
Note:
2022-10-09 21:23:55 +08:00
2024-04-15 10:03:49 +08:00
- It does not support `Replace` features.
2022-10-09 21:23:55 +08:00
2022-01-24 14:41:23 +08:00
# Custom Drivers
2024-04-15 10:03:49 +08:00
It's quick and easy, please refer to current driver source.
2022-01-24 14:41:23 +08:00
It's quite appreciated if any PR for new drivers support into current repo.