generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from envor/main
add copy function
- Loading branch information
Showing
8 changed files
with
168 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Envor\SchemaMacros\MariaDb; | ||
|
||
use Stringable; | ||
|
||
/** | ||
* determine if the database exists | ||
* | ||
* @param string|Stringable $database | ||
* | ||
* @mixin \Illuminate\Database\Schema\MariaDbBuilder | ||
* | ||
* @return bool | ||
*/ | ||
class MariaDbCopyTable | ||
{ | ||
public function __invoke(): callable | ||
{ | ||
return function (string $from, ?string $to = null): mixed { | ||
$from = (string) $from; | ||
$to = $to ? (string) $to : $from.'_copy'; | ||
|
||
$copy = function ($from, $to) use (&$copy) { | ||
/** @var \Illuminate\Database\Schema\MariaDbBuilder $this */ | ||
if ($this->hasTable($to)) { | ||
$to = $to.'_copy'; | ||
|
||
return $copy($from, $to); | ||
} | ||
|
||
/** @var \Illuminate\Database\Schema\MariaDbBuilder $this */ | ||
return $this->getConnection()->statement("CREATE TABLE {$to} AS SELECT * FROM {$from}"); | ||
}; | ||
|
||
return $copy($from, $to); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Envor\SchemaMacros\MySql; | ||
|
||
use Stringable; | ||
|
||
/** | ||
* determine if the database exists | ||
* | ||
* @param string|Stringable $database | ||
* | ||
* @mixin \Illuminate\Database\Schema\MySqlBuilder | ||
* | ||
* @return bool | ||
*/ | ||
class MySqlCopyTable | ||
{ | ||
public function __invoke(): callable | ||
{ | ||
return function (string $from, ?string $to = null): mixed { | ||
$from = (string) $from; | ||
$to = $to ? (string) $to : $from.'_copy'; | ||
|
||
$copy = function ($from, $to) use (&$copy) { | ||
/** @var \Illuminate\Database\Schema\MySqlBuilder $this */ | ||
if ($this->hasTable($to)) { | ||
$to = $to.'_copy'; | ||
|
||
return $copy($from, $to); | ||
} | ||
|
||
/** @var \Illuminate\Database\Schema\MySqlBuilder $this */ | ||
return $this->getConnection()->statement("CREATE TABLE {$to} AS SELECT * FROM {$from}"); | ||
}; | ||
|
||
return $copy($from, $to); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Envor\SchemaMacros\SQLite; | ||
|
||
use Stringable; | ||
|
||
/** | ||
* determine if the database exists | ||
* | ||
* @param string|Stringable $database | ||
* | ||
* @mixin \Illuminate\Database\Schema\SQLiteBuilder | ||
* | ||
* @return bool | ||
*/ | ||
class SQLiteCopyTable | ||
{ | ||
public function __invoke(): callable | ||
{ | ||
return function (string $from, ?string $to = null): mixed { | ||
$from = (string) $from; | ||
$to = $to ? (string) $to : $from.'_copy'; | ||
|
||
$copy = function ($from, $to) use (&$copy) { | ||
/** @var \Illuminate\Database\Schema\SQLiteBuilder $this */ | ||
if ($this->hasTable($to)) { | ||
$to = $to.'_copy'; | ||
|
||
return $copy($from, $to); | ||
} | ||
|
||
/** @var \Illuminate\Database\Schema\SQLiteBuilder $this */ | ||
return $this->getConnection()->statement("CREATE TABLE {$to} AS SELECT * FROM {$from}"); | ||
}; | ||
|
||
return $copy($from, $to); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters