haxetink / tink_sql

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

Extendable Table class? #20

Open kevinresol opened 7 years ago

kevinresol commented 7 years ago

I found myself writing the same query such as db.user.where(user.id == id).first() again and again. I wonder if it is possible to extend the generated table and add methods like db.user.get(id)

back2dos commented 7 years ago

Static extensions should work ;)

But yeah, let's see what we can do.

kevinresol commented 7 years ago

Static extensions should work ;)

I wonder what is the type of the generated table? Is it tink.sql.Table<User>?

kevinresol commented 7 years ago

Ok I figured it out:


class UserTableTools {
    public static function get(table:Table<{user:User}>, id:Id<User>)
        return table.where(user.id == id).first();
}