21 declare(strict_types=1);
44 private static $packaged;
47 return self::$packaged;
51 self::$packaged = __CLASS__ !==
'poggit\libasynql\libasynql';
54 echo Terminal::$COLOR_YELLOW .
"Warning: Use of unshaded libasynql detected. Debug mode is enabled. This may lead to major performance drop. Please use a shaded package in production. See https://poggit.pmmp.io/virion for more information.\n";
58 private function __construct(){
71 public static function create(Plugin $plugin, $configData, array $sqlMap,
bool $logQueries = null) :
DataConnector{
73 throw new ConfigException(
"Database settings are missing or incorrect");
76 $type = (string) $configData[
"type"];
93 $fileName = self::resolvePath($plugin->getDataFolder(), $configData[
"sqlite"][
"file"] ??
"data.sqlite");
107 if(!isset($configData[
"mysql"])){
124 if(!isset($dialect, $factory, $sqlMap[$dialect])){
125 throw new ConfigException(
"Unsupported database type \"$type\". Try \"sqlite\" or \"mysql\".");
128 $pool =
new SqlThreadPool($factory, $configData[
"worker-limit"] ?? 1);
129 while(!$pool->connCreated()){
132 if($pool->hasConnError()){
137 foreach(
is_string($sqlMap[$dialect]) ? [$sqlMap[$dialect]] : $sqlMap[$dialect] as $file){
138 $connector->loadQueryFile($plugin->getResource($file));
143 private static function resolvePath(
string $folder,
string $path) : string{
144 if($path{0} ===
"/"){
147 if(Utils::getOS() ===
"win"){
148 if($path{0} ===
"\\" || $path{1} ===
":"){
152 return $folder . $path;
163 libasynql::detectPackaged();
static createFactory(string $path)
static fromArray(array $array, ?string $defaultSchema=null)
static createFactory(MysqlCredentials $credentials)
static create(Plugin $plugin, $configData, array $sqlMap, bool $logQueries=null)