package thyyxxk.webserver.utils;

import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;

import java.util.function.Supplier;

public class DynamicDataUtil {

    public static <T> T db(String dbName, Supplier<T> supplier) {
        DynamicDataSourceContextHolder.push(dbName);
        try {
            return supplier.get();
        } finally {
            DynamicDataSourceContextHolder.poll();
        }
    }

}
