Commit Graph

1692 Commits

Author SHA1 Message Date
linbaozhong 4f8f829913 exist方法sql语句优化 (#2075)
本地没有mssql和oracle,所以没法测试,但是,mysql 使用select 1 from TABLENAME where CONDITION limit 1可能更好

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2075
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: linbaozhong <linbaozhong@noreply.gitea.io>
Co-committed-by: linbaozhong <linbaozhong@noreply.gitea.io>
2021-12-01 13:54:47 +08:00
RenKanai 885f582677 Fix to add session.statement.IsForUpdate check in Session.queryRows() (#2064)
# Issue
The 'for-update' query is executed to slave DB node.

# Example

```go
s := engineGroup.NewSession(); // create session from EngineGroup.
...

s.ForUpdate();

type User struct { ... };
var user User;
has, err := s.Get(&user); // executed to slave DB node.
...
```

Co-authored-by: rennnosuke <rennnosuke@noreply.gitea.io>
Co-authored-by: RenKanai <turutekab@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2064
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: RenKanai <rennnosuke@noreply.gitea.io>
Co-committed-by: RenKanai <rennnosuke@noreply.gitea.io>
2021-11-24 10:29:39 +08:00
Lunny Xiao f35ff7c2eb Make SQLType2Type support uint (#2071)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2071
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-11-19 12:32:55 +08:00
fanybook aea91cc7de add table & column comment for postgres(add table comment for mysql) (#2067)
让 postgres 支持字段注释,只在 v1.2.5 上测试过(不知道怎么 import master)

发现 master 分支好像大改了?模式表名带 schema 了

使用方式和 mysql 相同
```go
	type User struct {
		Id int64	`xorm:"pk autoincr"`
		Name string `json:"name" xorm:"not null default '' varchar(50) index(name_age) comment('用户 (it''s) 1; 名')"`
		Salt string
		Age int		`json:"age" xorm:"not null default 0 int(10) index(name_age) comment('年龄')"`
		Passwd string `xorm:"varchar(200)"`
		CreatedAt time.Time `xorm:"created"`
		UpdatedAt time.Time `xorm:"updated"`
	}

	_ = engine.Sync(new(User))

    func (model User) TableComment() string {
    	return "表注释"
    }
```

Co-authored-by: fanybook <fanybook@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2067
Co-authored-by: fanybook <fanybook@noreply.gitea.io>
Co-committed-by: fanybook <fanybook@noreply.gitea.io>
2021-11-12 20:58:05 +08:00
stepbystep2 a22f5dce83 少了个`.` (#2068)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2068
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: stepbystep2 <stepbystep2@noreply.gitea.io>
Co-committed-by: stepbystep2 <stepbystep2@noreply.gitea.io>
2021-11-09 17:55:37 +08:00
RenKanai 5feff03a17 Fix README.md: Sync2 -> Sync (#2065)
Co-authored-by: rennnosuke <rennnosuke@noreply.gitea.io>
Co-authored-by: RenKanai <turutekab@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2065
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: RenKanai <rennnosuke@noreply.gitea.io>
Co-committed-by: RenKanai <rennnosuke@noreply.gitea.io>
2021-10-29 17:31:07 +08:00
rennnosuke 26f9d619cc Fix new-lined query execution in master DB node. (#2066)
# Issue
Such a following query is executed in master DB node with EngineGroup.

```go
s := engineGroup.NewSession(); // create session from EngineGroup.

sql := `
SELECT * FROM USER;
`;

type User struct { ... };
var users []User;
err := s.Sql(sql).Find(&users); // executed to master DB node.

```

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2066
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: rennnosuke <rennnosuke@noreply.gitea.io>
Co-committed-by: rennnosuke <rennnosuke@noreply.gitea.io>
2021-10-28 21:21:38 +08:00
Lunny Xiao 40a135948b New Prepare useage (#2061)
Fix #2060, Three ways to use the `Prepare`.

The first

```go
engine.Prepare().Where().Get()
```

The second

```go
sess := engine.NewSession()
defer sess.Close()

sess.Prepare().Where().Get()

sess.Prepare().Where().Get()
```

The third
```go
sess := engine.NewSession()
defer sess.Close()

sess.Begin()

sess.Prepare().Where().Get()

sess.Prepare().Where().Get()

sess.Commit()
```

Or

```go
sess := engine.NewSession()
defer sess.Close()

sess.Begin()

sess.Prepare().Insert()

sess.Prepare().Insert()

sess.Commit()
```

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2061
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-10-20 08:53:30 +08:00
Lunny Xiao b350c289f8 Fix missing quote on modifycolumnSQL (#2058)
Fix #2054

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2058
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-09-29 20:07:55 +08:00
Lunny Xiao bd5cd8cab7 Fix bug of dameng scan (#2056)
Fix #2055

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2056
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-09-24 21:45:47 +08:00
undefined_ss 0de285680b fix ctx override bug (#2053)
详情请参考工单:https://gitea.com/xorm/xorm/issues/2052

Co-authored-by: undefined_ss <sununiq@163.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2053
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: undefined_ss <undefined_ss@noreply.gitea.io>
Co-committed-by: undefined_ss <undefined_ss@noreply.gitea.io>
2021-09-23 20:22:14 +08:00
Lunny Xiao fd26f415ca Add test for mysql tls (#2049)
Fix #1495

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2049
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-09-17 18:47:30 +08:00
Lunny Xiao 6761699036 Fix bug of Rows (#2048)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2048
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-09-16 23:59:36 +08:00
Lunny Xiao 4656a87f2f Fix bug (#2046)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2046
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-09-13 15:19:59 +08:00
Lunny Xiao 16cf2442f6 Some performance optimization for get (#2043)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2043
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-09-07 16:03:08 +08:00
daisuzu 78309606d4 fix panic when `Iterate()` fails (#2040)
not to call `rows.Err()`

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2040
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: daisuzu <daisuzu@noreply.gitea.io>
Co-committed-by: daisuzu <daisuzu@noreply.gitea.io>
2021-09-07 09:23:16 +08:00
Lunny Xiao 045abb07df Expose ScanString / ScanInterface and etc (#2039)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2039
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-08-27 17:10:16 +08:00
finelog e5c89cf55e fix panic when convert sql and args with nil time.Time pointer (#2038)
this pr fix a panic, when using nil time.Time pointer for input.
not sure if there are others similar code.
please review it, thanks!

Co-authored-by: finelog <kaicltw@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2038
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: finelog <finelog@noreply.gitea.io>
Co-committed-by: finelog <finelog@noreply.gitea.io>
2021-08-26 00:03:18 +08:00
Lunny Xiao 0a429a241d Drop sync function and rename sync2 to sync (#2018)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2018
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-08-24 17:13:17 +08:00
Lunny Xiao d92fb412ee Make Get and Rows.Scan accept multiple parameters (#2029)
Now the below behaviours are allowed.

```Go
var id int64
var name string
has, err := engine.Table(&user).Cols("id", "name").Get(&id, &name)
// SELECT id, name FROM user LIMIT 1
```

```Go
rows, err := engine.Cols("name", "age").Rows(&User{Name:name})
// SELECT * FROM user
defer rows.Close()
for rows.Next() {
    var name string
    var age int
    err = rows.Scan(&name, &age)
}
```

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2029
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-08-24 15:42:34 +08:00
Lunny Xiao c29b9649a9 Add dameng support (#2007)
driver: https://gitee.com/travelliu/dm
docker: https://download.dameng.com/eco/dm8/dm8_docker.tar

fix #1837

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2007
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-08-24 13:46:08 +08:00
yedf 7cd6a74c9f expose sql.Tx (#2036)
Co-authored-by: yedongfu <dongfuye@163.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2036
Co-authored-by: yedf <yedf@noreply.gitea.io>
Co-committed-by: yedf <yedf@noreply.gitea.io>
2021-08-21 11:30:31 +08:00
Lunny Xiao 7d458b4fcf refactor create table for postgres (#2034)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2034
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-08-14 10:57:47 +08:00
Lunny Xiao dbc2de380b Refactor find (#2031)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2031
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-08-11 21:17:23 +08:00
Lunny Xiao 289c27ebec
add changelog for 1.2.2 2021-08-11 09:29:27 +08:00
Lunny Xiao cace6862e2 Move convert back to xorm.io/xorm/convert (#2030)
Since `conversion.Conversion` has been referenced by external package, it should not be moved as internal package.

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2030
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-08-10 23:20:53 +08:00
Lunny Xiao fae164488c Fix problem on README (#2028)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2028
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-08-08 15:35:44 +08:00
Lunny Xiao 3a8ae761c5
Add changelog for v1.2.1 2021-08-08 11:01:02 +08:00
Lunny Xiao ad1a386b5e Fix wrong comment (#2027)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2027
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-08-08 11:00:11 +08:00
Lunny Xiao 4499c8c5b5 Fix import file bug (#2025)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2025
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-08-06 11:26:22 +08:00
Lunny Xiao bd1ca33ea5 Update docs for pgx (#2024)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2024
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-08-05 14:47:25 +08:00
Lunny Xiao 0b3cc25a10 Add pgx driver support (#1795)
Fix #858

Reviewed-on: https://gitea.com/xorm/xorm/pulls/1795
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-08-05 14:04:11 +08:00
Lunny Xiao 42c2f158e8 Fix timesatmp (#2021)
Now `Datetime` support `Datime(6)` to indicate the time scale. For different database , the max scale is not different.

`Datetime` means `Datetime(0)`.

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2021
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-08-04 16:12:10 +08:00
Lunny Xiao f22b0cc369
Update changelog for 1.2.0 2021-08-04 09:20:54 +08:00
Lunny Xiao 2afa222871 Fix deleted column (#2014)
Fix #2013

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2014
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-07-29 19:51:10 +08:00
Lunny Xiao aeed22016f Support batch insert map (#2019)
Fix #1767

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2019
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-07-29 16:12:09 +08:00
Lunny Xiao 4383669bcd Fix DBMetas returned unsigned tinyint (#2017)
Fix #2011

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2017
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-07-29 11:04:43 +08:00
Lunny Xiao 5240459858 Move assign functions to convert package (#2015)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2015
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-07-28 15:15:35 +08:00
Lunny Xiao eb6d3b1637 Make drone faster (#2008)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2008
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-07-28 11:41:58 +08:00
Lunny Xiao c02a1bf00c Fix postgres driver datasource name parse (#2012)
Fix #2010

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2012
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-07-28 10:03:09 +08:00
Andrew Thornton d973423802 Fix issue with byte representation in MSSQL (#1957)
There is a missing cast to string in BuildUpdates which leads to a failure
to call str2ucs and ucs2str for converts on MSSQL.

Ref: https://github.com/go-gitea/gitea/issues/16252

Signed-off-by: Andrew Thornton <art27@cantab.net>

Reviewed-on: https://gitea.com/xorm/xorm/pulls/1957
Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-committed-by: Andrew Thornton <art27@cantab.net>
2021-07-23 09:01:49 +08:00
Andrew Thornton ad4830f531 Remove default length of 50 for Blob (#1959)
There is an odd inconsistency with default blob sizes - this PR only sets the
default size for bytea and binary.

Signed-off-by: Andrew Thornton <art27@cantab.net>

Reviewed-on: https://gitea.com/xorm/xorm/pulls/1959
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-committed-by: Andrew Thornton <art27@cantab.net>
2021-07-23 08:59:53 +08:00
Lunny Xiao 6f79e06376 Fix master/slave bug (#2004)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2004
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-07-22 11:07:53 +08:00
Lunny Xiao 47cfe0347f Add test for limit with query (#1787)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/1787
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-07-21 21:13:15 +08:00
Lunny Xiao 0f3f4ea7fb Update docs (#2003)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2003
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-07-21 19:17:50 +08:00
Lunny Xiao 107bee4eb4 refactor conversion (#2001)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2001
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-07-21 11:46:41 +08:00
Lunny Xiao e323971011 refactor some code (#2000)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2000
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-07-21 00:12:20 +08:00
Lunny Xiao a7e010df2d refactor insert condition generation (#1998)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/1998
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-07-20 13:46:24 +08:00
Lunny Xiao 86775af2ec refactor and add setjson function (#1997)
Fix #1992

Reviewed-on: https://gitea.com/xorm/xorm/pulls/1997
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-07-19 13:43:53 +08:00
raizen666 5950824e37 Support build flag go-json to replace default json (#1982)
`go build -tags=gojson` to use `github.com/goccy/go-json` as default json handler

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/1982
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: raizen666 <raizen666@noreply.gitea.io>
Co-committed-by: raizen666 <raizen666@noreply.gitea.io>
2021-07-19 12:49:50 +08:00