go-jet / jet

Type safe SQL builder with code generation and automatic query result data mapping
Apache License 2.0
2.52k stars 118 forks source link

Deployed binary gives - jet: Error 1146 (42S02): Table '<generated in dev>.<my table>' doesn't exist) #287

Closed robdeacon closed 10 months ago

robdeacon commented 10 months ago

Describe the bug When deploying binary to a Linux server the log gives - jet: Error 1146 (42S02): Table '.' doesn't exist)

Environment (please complete the following information):

Code snippet

stmt := SELECT(
    TblgoProfile.StrName,
    TblgoProfile.StrDesc,
    TblgoProfile.IntTaskTypeID,
    TblgoTask.ID.AS("TaskID"),
    TblgoTask.IntprofileidFk,
    TblgoTask.IntStatusID,
    TblgoTask.IntclientidFk,
    TblgoTask.IntkeyFk,
    TblgoTask.JsonData,
    TblgoTask.IntRunTimes,
    TblgoTask.Timestamp,
    TblgoProfile.ID.AS("TblgoProfile.ID"),
    TblgoProfile.JsonParams,
    TblgoProfile.Timestamp,
).FROM(
    TblgoTask.LEFT_JOIN(TblgoProfile, TblgoProfile.ID.EQ(TblgoTask.IntprofileidFk)),
).WHERE(
    TblgoTask.IntStatusID.LT(Int(3)),
)
var dest TheTasks

err := stmt.Query(s.db, &dest)

if err != nil {

    return dest, fmt.Errorf("getNextTasks2 Query error: %w", err)
}

Expected behaviour Generated go-jet folders and files without issue on Dev machine (Windows) runs no problem. When i deploy a compiled Linux binary i get the following error in the logs. "getNextTasks2 Query error jet: Error 1146 (42S02): Table 'mydevdb.tblgo_task' doesn't exist) "

The mydevdb is the database used on the Dev machine. Looks like go-jet doesn't support deployed binaries using different named databases? Or I cannot see how that would work as the generated files all have the Dev mydevdb. I can't use the same database name as i need to deploy this to different named databases in the same target environment. If there is a way please let me know.

For debugging i did add an empty db called mydevdb to my target so I can understand better, hence the above.

houten11 commented 10 months ago

To change target database name, you can use global UseSchema method. For instance:

import "path/to/generated/table"

func main() { // or init
    table.UseSchema("prod_db")

}
robdeacon commented 10 months ago

To change target database name, you can use global UseSchema method. For instance:

import "path/to/generated/table"

func main() { // or init
    table.UseSchema("prod_db")

}

Thank you for this. I must have missed this if that was in the examples.