haxetink / tink_sql

SQL embedded into Haxe
MIT License
53 stars 16 forks source link

update SQL query error. #99

Closed sonygod closed 4 years ago

sonygod commented 4 years ago
import tink.sql.Types;

typedef Customer = {
    @:autoIncrement @:primary public var id(default, null):Id<Customer>;
    public var avatar(default, null):VarChar<50>;
    public var nickname(default, null):VarChar<50>;
    public var user_login(default, null):VarChar<50>;
    public var openid(default, null):VarChar<50>;
    public var money(default, null):Float;
    public var last_login_ip(default, null):VarChar<50>;
    public var club_id(default, null):Int;
    public var mobile(default, null):VarChar<11>;
    public var coins(default, null):Float;
    public var staticCoins(default, null):Float;
    public var referenceID(default, null):Float;
    public var level(default, null):Int;
}

class Db extends tink.sql.Database {
    @:table("fa_customer") var user:Customer;
}

///

static function testUpdate() {
    return db.user.update(function (u) return [u.money.set(u.money+10000)],{where:function 
   (u) return u.id>5140});
}

// -D sql_debug

  UPDATE `fa_customer` SET`money` = (`user`.`money` + 10000) WHERE (`user`.`id` > 5140)
sonygod commented 4 years ago
import tink.sql.Types;

typedef Customer = {
    @:autoIncrement @:primary public var id(default, null):Id<Customer>;
    public var avatar(default, null):VarChar<50>;
    public var nickname(default, null):VarChar<50>;
    public var user_login(default, null):VarChar<50>;
    public var openid(default, null):VarChar<50>;
    public var money(default, null):Float;
    public var last_login_ip(default, null):VarChar<50>;
    public var club_id(default, null):Int;
    public var mobile(default, null):VarChar<11>;
    public var coins(default, null):Float;
    public var staticCoins(default, null):Float;
    public var referenceID(default, null):Float;
    public var level(default, null):Int;
}

class Db extends tink.sql.Database {
    @:table("fa_customer") var user:Customer;
}

//------------------------------

static function testUpdate() {
    return db.user.update(function (u) return [u.money.set(u.money+10000)],{where:function (u) return u.id>5140});
}

//---dump sql

   UPDATE `fa_customer` SET`money` = (`user`.`money` + 10000) WHERE (`user`.`id` > 5140)
kevinresol commented 4 years ago

Summary: Query builder didn't pick up the table name specified in @:table

benmerckx commented 4 years ago

Same for inserts

benmerckx commented 4 years ago

Closed in 9ddc2be