go-ozzo / ozzo-dbx

A Go (golang) package that enhances the standard database/sql package by providing powerful data retrieval methods as well as DB-agnostic query building capabilities.
MIT License
638 stars 91 forks source link

Configurable table prefix #69

Closed kPshi closed 4 years ago

kPshi commented 6 years ago

Allows to set a TableMapper (similar to the FieldMapper) field in DB which then may return different table names even within the same process for different DB configurations. The GetTableName function has been renamed in order to match the naming of DefaultFieldMapFunc and in order to prevent hard to find bugs later on.

Usages of GetTableName should ideally rewritten to use

DB.TableMapper

For setting a prefix per instance of DB use

db := NewFromDB(myPlainDB, "mysql")
db.TableMapper = func(a interface{}) string {
    return "myprefix_" + DefaultTableMapFunc(a)
}
coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.02%) to 89.188% when pulling 33fd39f2aefb53803c4315bed489b6524e9de68f on kPshi:configurable_table_prefix into b7add2e1fdabd9d095d2b2b0bffb5d3d6f5834f7 on go-ozzo:master.

qiangxue commented 4 years ago

Thank you for your contribution! I've merged your code manually.