These are chat archives for jinzhu/gorm

21st
Mar 2016
Matthias Loibl
@metalmatze
Mar 21 2016 01:48
Is there a way to add something like ORDER BY date LIMIT 1 to Preload? I want to preload, but I just want this one item.
Matthias Loibl
@metalmatze
Mar 21 2016 01:59
Ok, just found out, I don’t want to simply append the SQL above.
From the list of IDs I get I want to just preload one specifig related object and not all related.
Thomas Boerger
@tboerger
Mar 21 2016 06:33
@MetalMatze maybe build just a join?
Matthias Loibl
@metalmatze
Mar 21 2016 11:39
@tboerger You’re right. It’s probably the best way to go. Thanks!
Thomas Boerger
@tboerger
Mar 21 2016 11:51
:)
Thomas Boerger
@tboerger
Mar 21 2016 12:04
@jinzhu can you say how big the efford is to make https://github.com/cznic/ql/blob/master/driver/driver.go supported?
sqlite sucks... it's more or less impossible to keep a project with it static linked or portable
Matthias Loibl
@metalmatze
Mar 21 2016 12:09
That would be awesome!
Thomas Boerger
@tboerger
Mar 21 2016 12:09
i need that...
but currently i have no odea what we need to fix on gorm side...
Thomas Boerger
@tboerger
Mar 21 2016 12:16
the tests are so damn slow with sqlite beside that it's not really portable
Jinzhu
@jinzhu
Mar 21 2016 12:32
Yes, you could give it a try.
Thomas Boerger
@tboerger
Mar 21 2016 12:32
already on it :D
s.db.QueryRow("SELECT COUNT(*) FROM __Table WHERE Name = ?", tableName).Scan(&count) should be already cool, now i'm on columns from the __Column table ;)
but i have no idea about the types yet... need to read more specs of ql
Jinzhu
@jinzhu
Mar 21 2016 12:33
;) good luck
Thomas Boerger
@tboerger
Mar 21 2016 12:33
i would love it if it works :D
nice fully integrated database without beeing forced to use cgo
Jinzhu
@jinzhu
Mar 21 2016 12:34
yes, good for testing
Thomas Boerger
@tboerger
Mar 21 2016 12:34
and ql also provides a inmemory handler
mdb, err := sql.Open("ql", "memory://mem.db")
Jinzhu
@jinzhu
Mar 21 2016 12:35
cool
Matthias Loibl
@metalmatze
Mar 21 2016 12:36
@tboerger Ping me if you need some help.
Thomas Boerger
@tboerger
Mar 21 2016 12:36
func (s ql) HasTable(tableName string) bool {
  var count int
  s.db.QueryRow("SELECT COUNT(*) FROM __Table WHERE Name = ?", tableName).Scan(&count)
  return count > 0
}

func (s ql) HasColumn(tableName string, columnName string) bool {
  var count int
  s.db.QueryRow("SELECT COUNT(*) FROM __Column WHERE TableName = ? AND Name = ?", tableName, columnName).Scan(&count)
  return count > 0
}
the beginning is quite easy :P
Thomas Boerger
@tboerger
Mar 21 2016 12:42
need to try it but i think beside the types it's already looking cool 8)
i have already created jinzhu/gorm#917 but marked it as WIP
i will give it a try so far, i'm absolutely sure that the types need more tweaking.
Thomas Boerger
@tboerger
Mar 21 2016 12:56
a lot of (1:13 unexpected string literal, expected table name or one of [IF, identifier])
Thomas Boerger
@tboerger
Mar 21 2016 13:32
@jinzhu how can i overwrite the CREATE TABLE statement? is that possible within the dialect definition?
Jinzhu
@jinzhu
Mar 21 2016 13:38
not possible
why need to do that?
ah wait... that should work
let me get more debug information
i think it just doesnt like the quoting
Jinzhu
@jinzhu
Mar 21 2016 13:42
you could overwrite the Quote method for the dialect ;)
Thomas Boerger
@tboerger
Mar 21 2016 13:42
yeah doing that to confirm that this is the issue
but damn, i need more transactions...
and a proper type mapping...
@MetalMatze can you see anything if there are primary keys within ql?
Matthias Loibl
@metalmatze
Mar 21 2016 13:48
hmm, not if I look through the doc you posted.
Thomas Boerger
@tboerger
Mar 21 2016 13:54
@jinzhu it wont work because of the hard coded , PRIMARY KEY (%v)
CREATE TABLE comments (id uint,created_at time,updated_at time,deleted_at time,post_id int64,content string , PRIMARY KEY (id)) CREATE TABLE cats (id int,name string , PRIMARY KEY (id)) CREATE TABLE dogs (id int,name string , PRIMARY KEY (id)) CREATE TABLE toys (id int,name string,owner_id int,owner_type string , PRIMARY KEY (id)) panic: No error should happen when create table, but got 1:367 unexpected identifier, expected one of [$end, ')', ',', ';', '=', LIMIT, OFFSET, ORDER, bigint, bigrat, blob, bool, byte, complex128, complex64, duration, float, float32, float64, int, int16, int32, int64, int8, rune, string, time, uint, uint16, uint32, uint64, uint8]
Thomas Boerger
@tboerger
Mar 21 2016 14:14
solved the biggest issue... now i just need transactions around database changing parts :(
(attempt to update the DB outside of a transaction)
This message was deleted
@jinzhu https://github.com/jinzhu/gorm/pull/917/files what do you think about those changes?
Thomas Boerger
@tboerger
Mar 21 2016 14:40
@jinzhu does it make sense to also add a function that checks if the database needs transactions around database changes? or is that out of scope?