Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Integrated ql dialect #917

Closed
wants to merge 5 commits into from

Conversation

Projects
None yet
3 participants
@tboerger
Copy link

tboerger commented Mar 21, 2016

I have marked this PR as work in progress because I have not tested it yet. But I want to gather feedback as soon as possible.

Thomas Boerger
@tboerger

This comment has been minimized.

Copy link
Author

tboerger commented Mar 21, 2016

# GORM_DIALECT=ql go test
testing ql...

(attempt to update the DB outside of a transaction) 
[2016-03-21 13:55:29]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 13:55:29]  

(1:13 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:13 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:13 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:13 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:13 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:13 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:13 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:13 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:13 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:13 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:13 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:13 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:13 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:13 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:13 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:13 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:13 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:13 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:15 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:15 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  

(1:15 unexpected string literal, expected table name or one of [IF, identifier]) 
[2016-03-21 13:55:29]  
panic: No error should happen when create table, but got 1:15 unexpected string literal, expected table name or one of [IF, identifier]

goroutine 1 [running]:
panic(0xb19f00, 0xc82000b380)
    /usr/lib64/go/src/runtime/panic.go:464 +0x3e6
github.com/jinzhu/gorm_test.runMigration()
    /home/tboerger/Projects/golang/src/github.com/jinzhu/gorm/migration_test.go:239 +0xf60
github.com/jinzhu/gorm_test.init.1()
    /home/tboerger/Projects/golang/src/github.com/jinzhu/gorm/main_test.go:43 +0x251
github.com/jinzhu/gorm_test.init()
    /home/tboerger/Projects/golang/src/github.com/jinzhu/gorm/utils_test.go:30 +0x94
main.init()
    github.com/jinzhu/gorm/_test/_testmain.go:316 +0x4f
exit status 2
FAIL    github.com/jinzhu/gorm  0.036s

Sad initial results...

@tboerger

This comment has been minimized.

Copy link
Author

tboerger commented Mar 21, 2016

Solved most issues, but I'm not sure how to wrap all the CREATE TABLE and CREATE INDEX instructions into transactions:

# GORM_DIALECT=ql go test
testing ql...

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:19:51]  
panic: No error should happen when create table, but got attempt to update the DB outside of a transaction

goroutine 1 [running]:
panic(0xb1aa80, 0xc8200e5ec0)
    /usr/lib64/go/src/runtime/panic.go:464 +0x3e6
github.com/jinzhu/gorm_test.runMigration()
    /home/tboerger/Projects/golang/src/github.com/jinzhu/gorm/migration_test.go:239 +0xf60
github.com/jinzhu/gorm_test.init.1()
    /home/tboerger/Projects/golang/src/github.com/jinzhu/gorm/main_test.go:43 +0x251
github.com/jinzhu/gorm_test.init()
    /home/tboerger/Projects/golang/src/github.com/jinzhu/gorm/utils_test.go:30 +0x94
main.init()
    github.com/jinzhu/gorm/_test/_testmain.go:316 +0x4f
exit status 2
FAIL    github.com/jinzhu/gorm  0.042s
@tboerger

This comment has been minimized.

Copy link
Author

tboerger commented Mar 21, 2016

Ok, now it's getting much more complicated. Now I get this with the following patch on top of my PR:

# GORM_DIALECT=ql go test
testing ql...

(DROP TABLE: table animals does not exist) 
[2016-03-21 15:38:24]  

(DROP TABLE: table user_languages does not exist) 
[2016-03-21 15:38:24]  

(no RowsAffected available after DDL statement) 
[2016-03-21 15:38:24]  

(DROP TABLE: table emails does not exist) 
[2016-03-21 15:38:24]  

(DROP TABLE: table addresses does not exist) 
[2016-03-21 15:38:24]  

(DROP TABLE: table credit_cards does not exist) 
[2016-03-21 15:38:24]  

(DROP TABLE: table companies does not exist) 
[2016-03-21 15:38:24]  

(DROP TABLE: table roles does not exist) 
[2016-03-21 15:38:24]  

(DROP TABLE: table languages does not exist) 
[2016-03-21 15:38:24]  

(DROP TABLE: table hn_posts does not exist) 
[2016-03-21 15:38:24]  

(DROP TABLE: table engadget_posts does not exist) 
[2016-03-21 15:38:24]  

(DROP TABLE: table animals does not exist) 
[2016-03-21 15:38:24]  

(DROP TABLE: table users does not exist) 
[2016-03-21 15:38:24]  

(DROP TABLE: table join_tables does not exist) 
[2016-03-21 15:38:24]  

(DROP TABLE: table posts does not exist) 
[2016-03-21 15:38:24]  

(DROP TABLE: table categories does not exist) 
[2016-03-21 15:38:24]  

(DROP TABLE: table comments does not exist) 
[2016-03-21 15:38:24]  

(DROP TABLE: table cats does not exist) 
[2016-03-21 15:38:24]  

(DROP TABLE: table dogs does not exist) 
[2016-03-21 15:38:24]  

(DROP TABLE: table toys does not exist) 
[2016-03-21 15:38:24]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:38:24]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:38:24]  

(attempt to update the DB outside of a transaction) 
[2016-03-21 15:38:24]  
panic: No error should happen when create table, but got attempt to update the DB outside of a transaction

goroutine 1 [running]:
panic(0xb1ab40, 0xc820491ab0)
    /usr/lib64/go/src/runtime/panic.go:464 +0x3e6
github.com/jinzhu/gorm_test.runMigration()
    /home/tboerger/Projects/golang/src/github.com/jinzhu/gorm/migration_test.go:249 +0xf7f
github.com/jinzhu/gorm_test.init.1()
    /home/tboerger/Projects/golang/src/github.com/jinzhu/gorm/main_test.go:43 +0x251
github.com/jinzhu/gorm_test.init()
    /home/tboerger/Projects/golang/src/github.com/jinzhu/gorm/utils_test.go:30 +0x94
main.init()
    github.com/jinzhu/gorm/_test/_testmain.go:316 +0x4f
exit status 2
FAIL    github.com/jinzhu/gorm  0.034s
diff --git a/migration_test.go b/migration_test.go
index 81fe4fd..7c18336 100644
--- a/migration_test.go
+++ b/migration_test.go
@@ -222,19 +222,29 @@ func getPreparedUser(name string, role string) *User {
 }

 func runMigration() {
-       if err := DB.DropTableIfExists(&User{}).Error; err != nil {
+       tx1 := DB.Begin()
+
+       if err := tx1.DropTableIfExists(&User{}).Error; err != nil {
                fmt.Printf("Got error when try to delete table users, %+v\n", err)
        }

+       tx1.Commit()
+       tx2 := DB.Begin()
+
        for _, table := range []string{"animals", "user_languages"} {
-               DB.Exec(fmt.Sprintf("drop table %v;", table))
+               tx2.Exec(fmt.Sprintf("drop table %v;", table))
        }

+       tx2.Commit()
+       tx3 := DB.Begin()
+
        values := []interface{}{&Product{}, &Email{}, &Address{}, &CreditCard{}, &Company{}, &Role{}, &Language{}, &HNPost{}, &EngadgetPost{}, &Animal{}, &User{}, &JoinTable{}, &Post{}, &Category{}, &Comment{}, &Cat{}, &Dog{}, &Toy{}}
        for _, value := range values {
-               DB.DropTable(value)
+               tx3.DropTable(value)
        }

+       tx3.Commit()
+
        if err := DB.AutoMigrate(values...).Error; err != nil {
                panic(fmt.Sprintf("No error should happen when create table, but got %+v", err))
        }
@cryptix

This comment has been minimized.

Copy link

cryptix commented Mar 28, 2016

Wow, cool! I nearly went into this blindly myself and checked PRs just by accident.

Looks very promising. I'll try it myself and see if I can come up with something for the outstanding issues.

Just one thing I saw so far: You are not checking the errs returned by tx.Exec() and tx.Commit() are you sure they run fine?

@iu0v1

This comment has been minimized.

Copy link

iu0v1 commented Apr 28, 2016

Awesome! I have subscribed :)

@cryptix

This comment has been minimized.

Copy link

cryptix commented Aug 20, 2016

hrm... Have looked at this again today but no progress. The transaction-requirement from ql for altering queries is a really hard block here.

Other than including new callbacks to hook all these kinds of actions and having a method on Scope to override sql.DB I don't see a way to proceed here, right now. :'<

@tboerger

This comment has been minimized.

Copy link
Author

tboerger commented Aug 20, 2016

That's why I have not continued on it yet :(

@iu0v1

This comment has been minimized.

Copy link

iu0v1 commented Aug 20, 2016

It is the saddest day this month ಥ_ಥ

@tboerger

This comment has been minimized.

Copy link
Author

tboerger commented Aug 21, 2016

If somebody got a good idea I'm open for it :)

@cryptix

This comment has been minimized.

Copy link

cryptix commented Aug 22, 2016

We could do the anarchic thing and just hammer it in but I'd prefer some feedback from @jinzhu first.

@tboerger

This comment has been minimized.

Copy link
Author

tboerger commented Sep 13, 2016

I will close this PR for now since ql is pretty inactive and instead of that I will try to integrate https://github.com/pingcap/tidb as an embedded database.

@tboerger tboerger closed this Sep 13, 2016

@tboerger tboerger deleted the tboerger:feature/ql branch Sep 13, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.