gf/contrib/drivers/README.MD

124 lines
2.4 KiB
Plaintext
Raw Normal View History

2022-01-24 14:47:22 +08:00
# drivers
2022-05-13 21:54:24 +08:00
Powerful database drivers for package gdb.
# Installation
2022-05-13 21:54:24 +08:00
Let's take `mysql` for example.
```shell
2022-05-13 21:54:24 +08:00
go get -u github.com/gogf/gf/contrib/drivers/mysql/v2
# 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
```
Choose and import the driver to your project:
```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`:
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.
}
```
# Supported Drivers
2022-04-12 21:31:51 +08:00
## MySQL/MariaDB/TiDB
```go
import _ "github.com/gogf/gf/contrib/drivers/mysql/v2"
```
## SQLite
```go
import _ "github.com/gogf/gf/contrib/drivers/sqlite/v2"
```
### cgo version for 32-bit windows
```go
import _ "github.com/gogf/gf/contrib/drivers/sqlitecgo/v2"
```
## PostgreSQL
```go
import _ "github.com/gogf/gf/contrib/drivers/pgsql/v2"
```
Note:
- It does not support `Replace` features.
## SQL Server
```go
import _ "github.com/gogf/gf/contrib/drivers/mssql/v2"
```
Note:
- It does not support `Replace` features.
- It does not support `LastInsertId`.
- It supports server version >= `SQL Server2005`
- 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.
## Oracle
```go
import _ "github.com/gogf/gf/contrib/drivers/oracle/v2"
```
Note:
- It does not support `Replace` features.
- It does not support `LastInsertId`.
2022-04-12 21:31:51 +08:00
## ClickHouse
```go
2022-04-12 21:31:51 +08:00
import _ "github.com/gogf/gf/contrib/drivers/clickhouse/v2"
```
2022-04-12 21:31:51 +08:00
Note:
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.
- It does not support `RowsAffected` feature.
2022-04-12 21:31:51 +08:00
2022-09-26 22:11:13 +08:00
## DM
```go
2022-09-26 22:11:13 +08:00
import _ "github.com/gogf/gf/contrib/drivers/dm/v2"
```
Note:
- It does not support `Replace` features.
# Custom Drivers
It's quick and easy, please refer to current driver source.
It's quite appreciated if any PR for new drivers support into current repo.