fixing database connections
This commit is contained in:
@@ -28,6 +28,15 @@
|
|||||||
editor.addEventListener("trix-file-accept", (e) => {
|
editor.addEventListener("trix-file-accept", (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
editor.addEventListener("trix-before-initialize", (e) => {
|
||||||
|
Trix.config.blockAttributes.heading1.tagName = 'h2';
|
||||||
|
const { toolbarElement } = e.target
|
||||||
|
const h1Button = toolbarElement.querySelector("[data-trix-attribute=heading1]")
|
||||||
|
h1Button.insertAdjacentHTML("afterend", `<button style="text-indent: initial;padding: 14px 10px !important;" type="button" class="trix-button trix-button--icon" data-trix-attribute="heading3" title="Heading 3" tabindex="-1" data-trix-active="">H3</button>`)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
// onDestroy(() => {
|
// onDestroy(() => {
|
||||||
// editor.removeEventListener("trix-before-initialize")
|
// editor.removeEventListener("trix-before-initialize")
|
||||||
@@ -35,7 +44,13 @@
|
|||||||
|
|
||||||
|
|
||||||
Trix.config.blockAttributes.default.breakOnReturn = false
|
Trix.config.blockAttributes.default.breakOnReturn = false
|
||||||
console.log(Trix.config)
|
Trix.config.blockAttributes.heading3 = {
|
||||||
|
tagName: 'h3',
|
||||||
|
terminal: true,
|
||||||
|
breakOnReturn: true,
|
||||||
|
group: false
|
||||||
|
}
|
||||||
|
// console.log(Trix.config)
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,16 @@
|
|||||||
|
|
||||||
.cm-content{
|
.cm-content{
|
||||||
background-color: var(--p10);
|
background-color: var(--p10);
|
||||||
|
color: var(--p100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.cm-content{
|
.cm-content{
|
||||||
background-color: var(--p20);
|
background-color: var(--p20);
|
||||||
|
|
||||||
|
}
|
||||||
|
.ͼ4 .cm-line ::selection, .ͼ4 .cm-line::selection{
|
||||||
|
background: var(--p40) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cm-activeLine{
|
.cm-activeLine{
|
||||||
|
|||||||
@@ -22,6 +22,11 @@
|
|||||||
line-height: 30px;
|
line-height: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h3{
|
||||||
|
font-size: 18px;
|
||||||
|
line-height: 28px;
|
||||||
|
}
|
||||||
|
|
||||||
ul {
|
ul {
|
||||||
padding: 0 0 0 16px;
|
padding: 0 0 0 16px;
|
||||||
list-style: none outside none;
|
list-style: none outside none;
|
||||||
|
|||||||
+11
-11
@@ -3,7 +3,7 @@
|
|||||||
namespace Lucent\Account;
|
namespace Lucent\Account;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Lucent\Database\Database;
|
||||||
use Lucent\Primitive\Collection;
|
use Lucent\Primitive\Collection;
|
||||||
use PhpOption\Option;
|
use PhpOption\Option;
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ class UserRepo
|
|||||||
|
|
||||||
public function count(): int
|
public function count(): int
|
||||||
{
|
{
|
||||||
return DB::table("users")->count();
|
return Database::make()->table("users")->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,7 +20,7 @@ class UserRepo
|
|||||||
*/
|
*/
|
||||||
public function all(): Collection
|
public function all(): Collection
|
||||||
{
|
{
|
||||||
$usersData = DB::table("users")->get();
|
$usersData = Database::make()->table("users")->get();
|
||||||
|
|
||||||
$users = array_map(fn($userData) => $this->fromArray((array)$userData), $usersData->toArray());
|
$users = array_map(fn($userData) => $this->fromArray((array)$userData), $usersData->toArray());
|
||||||
return new Collection($users);
|
return new Collection($users);
|
||||||
@@ -31,14 +31,14 @@ class UserRepo
|
|||||||
{
|
{
|
||||||
$userData = toArray($user);
|
$userData = toArray($user);
|
||||||
$userData["roles"] = json_encode($userData["roles"]);
|
$userData["roles"] = json_encode($userData["roles"]);
|
||||||
DB::table("users")->insert($userData);
|
Database::make()->table("users")->insert($userData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(User $user): void
|
public function update(User $user): void
|
||||||
{
|
{
|
||||||
$userData = toArray($user);
|
$userData = toArray($user);
|
||||||
$userData["roles"] = json_encode($userData["roles"]);
|
$userData["roles"] = json_encode($userData["roles"]);
|
||||||
DB::table("users")->where("id", $user->id)->update($userData);
|
Database::make()->table("users")->where("id", $user->id)->update($userData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ class UserRepo
|
|||||||
{
|
{
|
||||||
$newToken = Token::new(32);
|
$newToken = Token::new(32);
|
||||||
|
|
||||||
DB::table("users")
|
Database::make()->table("users")
|
||||||
->where("id", $id)
|
->where("id", $id)
|
||||||
->update([
|
->update([
|
||||||
'loggedInAt' => Carbon::now()->toJson(),
|
'loggedInAt' => Carbon::now()->toJson(),
|
||||||
@@ -62,7 +62,7 @@ class UserRepo
|
|||||||
*/
|
*/
|
||||||
public function findByEmail(Email $email): Option
|
public function findByEmail(Email $email): Option
|
||||||
{
|
{
|
||||||
$user = DB::table("users")->where("email", $email->value())->first();
|
$user = Database::make()->table("users")->where("email", $email->value())->first();
|
||||||
|
|
||||||
if (empty($user)) {
|
if (empty($user)) {
|
||||||
return none();
|
return none();
|
||||||
@@ -76,7 +76,7 @@ class UserRepo
|
|||||||
*/
|
*/
|
||||||
public function findById(string $id): Option
|
public function findById(string $id): Option
|
||||||
{
|
{
|
||||||
$user = DB::table("users")->where("id", $id)->first();
|
$user = Database::make()->table("users")->where("id", $id)->first();
|
||||||
|
|
||||||
if (empty($user)) {
|
if (empty($user)) {
|
||||||
return none();
|
return none();
|
||||||
@@ -88,12 +88,12 @@ class UserRepo
|
|||||||
|
|
||||||
public function updateName(string $userId, Name $name): void
|
public function updateName(string $userId, Name $name): void
|
||||||
{
|
{
|
||||||
DB::table("users")->where("id", $userId)->update(["name" => $name->value]);
|
Database::make()->table("users")->where("id", $userId)->update(["name" => $name->value]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateEmail(string $userId, Email $email): void
|
public function updateEmail(string $userId, Email $email): void
|
||||||
{
|
{
|
||||||
DB::table("users")->where("id", $userId)->update(["email" => $email->value()]);
|
Database::make()->table("users")->where("id", $userId)->update(["email" => $email->value()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fromArray(array $data): User
|
public function fromArray(array $data): User
|
||||||
@@ -102,7 +102,7 @@ class UserRepo
|
|||||||
id: $data["id"],
|
id: $data["id"],
|
||||||
name: new Name($data["name"] ?? ""),
|
name: new Name($data["name"] ?? ""),
|
||||||
email: new Email($data["email"]),
|
email: new Email($data["email"]),
|
||||||
roles: json_decode($data["roles"] ?? "[]",true),
|
roles: json_decode($data["roles"] ?? "[]", true),
|
||||||
createdAt: $data["createdAt"],
|
createdAt: $data["createdAt"],
|
||||||
updatedAt: $data["updatedAt"],
|
updatedAt: $data["updatedAt"],
|
||||||
loggedInAt: $data["loggedInAt"] ?? null,
|
loggedInAt: $data["loggedInAt"] ?? null,
|
||||||
|
|||||||
@@ -2,15 +2,15 @@
|
|||||||
|
|
||||||
namespace Lucent\Command;
|
namespace Lucent\Command;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Lucent\Command\Data\CommandLogItem;
|
use Lucent\Command\Data\CommandLogItem;
|
||||||
|
use Lucent\Database\Database;
|
||||||
|
|
||||||
class CommandRepo
|
class CommandRepo
|
||||||
{
|
{
|
||||||
public function findBySignature($signature): ?CommandLogItem
|
public function findBySignature($signature): ?CommandLogItem
|
||||||
{
|
{
|
||||||
|
|
||||||
$row = DB::table("command_logs")->where("signature", $signature)->first();
|
$row = Database::make()->table("command_logs")->where("signature", $signature)->first();
|
||||||
if (empty($row)) {
|
if (empty($row)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -22,16 +22,16 @@ class CommandRepo
|
|||||||
{
|
{
|
||||||
$foundCommandLogItem = $this->findBySignature($commandLogItem->signature);
|
$foundCommandLogItem = $this->findBySignature($commandLogItem->signature);
|
||||||
if (empty($foundCommandLogItem)) {
|
if (empty($foundCommandLogItem)) {
|
||||||
DB::table("command_logs")->insert(toArray($commandLogItem));
|
Database::make()->table("command_logs")->insert(toArray($commandLogItem));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DB::table("command_logs")->where("signature", $commandLogItem->signature)->update(toArray($commandLogItem));
|
Database::make()->table("command_logs")->where("signature", $commandLogItem->signature)->update(toArray($commandLogItem));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function appendToLogs(string $signature, string $line): void
|
public function appendToLogs(string $signature, string $line): void
|
||||||
{
|
{
|
||||||
$res = DB::update(
|
Database::make()->update(
|
||||||
'update command_logs set logs = logs || ? where signature = ?',
|
'update command_logs set logs = logs || ? where signature = ?',
|
||||||
[$line, $signature]
|
[$line, $signature]
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace Lucent\Commands;
|
|||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Lucent\Database\Database;
|
||||||
|
|
||||||
class SetupDatabase extends Command
|
class SetupDatabase extends Command
|
||||||
{
|
{
|
||||||
@@ -27,7 +27,7 @@ class SetupDatabase extends Command
|
|||||||
|
|
||||||
private function tableUsers(): void
|
private function tableUsers(): void
|
||||||
{
|
{
|
||||||
Schema::create('users', function (Blueprint $table) {
|
Database::make()->getSchemaBuilder()->create('users', function (Blueprint $table) {
|
||||||
$table->uuid("id")->primary();
|
$table->uuid("id")->primary();
|
||||||
$table->string('name')->nullable();
|
$table->string('name')->nullable();
|
||||||
$table->string('email')->unique();
|
$table->string('email')->unique();
|
||||||
@@ -42,7 +42,7 @@ class SetupDatabase extends Command
|
|||||||
|
|
||||||
private function tableSessions(): void
|
private function tableSessions(): void
|
||||||
{
|
{
|
||||||
Schema::create('sessions', function (Blueprint $table) {
|
Database::make()->getSchemaBuilder()->create('sessions', function (Blueprint $table) {
|
||||||
$table->string('id')->primary();
|
$table->string('id')->primary();
|
||||||
$table->foreignId('user_id')->nullable()->index();
|
$table->foreignId('user_id')->nullable()->index();
|
||||||
$table->string('ip_address', 45)->nullable();
|
$table->string('ip_address', 45)->nullable();
|
||||||
@@ -54,7 +54,7 @@ class SetupDatabase extends Command
|
|||||||
|
|
||||||
private function tableRecords(): void
|
private function tableRecords(): void
|
||||||
{
|
{
|
||||||
Schema::create('records', function (Blueprint $table) {
|
Database::make()->getSchemaBuilder()->create('records', function (Blueprint $table) {
|
||||||
$table->uuid('id')->primary();
|
$table->uuid('id')->primary();
|
||||||
$table->string('schema');
|
$table->string('schema');
|
||||||
$table->string('status');
|
$table->string('status');
|
||||||
@@ -67,7 +67,7 @@ class SetupDatabase extends Command
|
|||||||
$table->index('search');
|
$table->index('search');
|
||||||
});
|
});
|
||||||
|
|
||||||
Schema::create('edges', function (Blueprint $table) {
|
Database::make()->getSchemaBuilder()->create('edges', function (Blueprint $table) {
|
||||||
$table->uuid('source');
|
$table->uuid('source');
|
||||||
$table->uuid('target');
|
$table->uuid('target');
|
||||||
$table->string('sourceSchema');
|
$table->string('sourceSchema');
|
||||||
@@ -81,7 +81,7 @@ class SetupDatabase extends Command
|
|||||||
|
|
||||||
private function tableRevisions(): void
|
private function tableRevisions(): void
|
||||||
{
|
{
|
||||||
Schema::create('revisions', function (Blueprint $table) {
|
Database::make()->getSchemaBuilder()->create('revisions', function (Blueprint $table) {
|
||||||
$table->uuid('id')->primary();
|
$table->uuid('id')->primary();
|
||||||
$table->uuid('recordId');
|
$table->uuid('recordId');
|
||||||
$table->string('schema');
|
$table->string('schema');
|
||||||
@@ -94,7 +94,7 @@ class SetupDatabase extends Command
|
|||||||
|
|
||||||
private function tableCommandLogs(): void
|
private function tableCommandLogs(): void
|
||||||
{
|
{
|
||||||
Schema::create('command_logs', function (Blueprint $table) {
|
Database::make()->getSchemaBuilder()->create('command_logs', function (Blueprint $table) {
|
||||||
$table->uuid('id')->primary();
|
$table->uuid('id')->primary();
|
||||||
$table->string('signature');
|
$table->string('signature');
|
||||||
$table->integer('pid')->nullable();
|
$table->integer('pid')->nullable();
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lucent\Database;
|
||||||
|
|
||||||
|
use Illuminate\Database\Connection;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class Database
|
||||||
|
{
|
||||||
|
public static function make(): Connection{
|
||||||
|
$dbConnection = config("lucent.database");
|
||||||
|
return DB::connection($dbConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php namespace Lucent\Edge;
|
<?php namespace Lucent\Edge;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\DB;
|
use Lucent\Database\Database;
|
||||||
use Lucent\LucentException;
|
use Lucent\LucentException;
|
||||||
use PDOException;
|
use PDOException;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
@@ -15,7 +15,7 @@ class EdgeRepo
|
|||||||
public function insert(Edge $edge): void
|
public function insert(Edge $edge): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
DB::table("edges")->insert($edge->toDB());
|
Database::make()->table("edges")->insert($edge->toDB());
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
if ($e->getCode() == 23505) {
|
if ($e->getCode() == 23505) {
|
||||||
throw new LucentException("Edge already exists");
|
throw new LucentException("Edge already exists");
|
||||||
@@ -34,7 +34,7 @@ class EdgeRepo
|
|||||||
{
|
{
|
||||||
$edgesDB = collect($edges)->map(fn($e) => $e->toDB())->toArray();
|
$edgesDB = collect($edges)->map(fn($e) => $e->toDB())->toArray();
|
||||||
try {
|
try {
|
||||||
DB::table("edges")->insert($edgesDB);
|
Database::make()->table("edges")->insert($edgesDB);
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
if ($e->getCode() == 23505) {
|
if ($e->getCode() == 23505) {
|
||||||
throw new LucentException("Edge already exists");
|
throw new LucentException("Edge already exists");
|
||||||
@@ -52,8 +52,8 @@ class EdgeRepo
|
|||||||
public function replaceForRecord(string $from, array $edges): void
|
public function replaceForRecord(string $from, array $edges): void
|
||||||
{
|
{
|
||||||
$edgesDB = collect($edges)->map(fn($e) => $e->toDB())->toArray();
|
$edgesDB = collect($edges)->map(fn($e) => $e->toDB())->toArray();
|
||||||
DB::table("edges")->where("source", $from)->delete();
|
Database::make()->table("edges")->where("source", $from)->delete();
|
||||||
DB::table("edges")->insert($edgesDB);
|
Database::make()->table("edges")->insert($edgesDB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -62,13 +62,13 @@ class EdgeRepo
|
|||||||
*/
|
*/
|
||||||
public function findAll(): array
|
public function findAll(): array
|
||||||
{
|
{
|
||||||
$edges = DB::table("edges")->get();
|
$edges = Database::make()->table("edges")->get();
|
||||||
return $edges->map([$this, 'mapEdge'])->toArray();
|
return $edges->map([$this, 'mapEdge'])->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findForSource(string $recordId): array
|
public function findForSource(string $recordId): array
|
||||||
{
|
{
|
||||||
$edges = DB::table("edges")->where("source", $recordId)->get();
|
$edges = Database::make()->table("edges")->where("source", $recordId)->get();
|
||||||
return $edges->map([$this, 'mapEdge'])->toArray();
|
return $edges->map([$this, 'mapEdge'])->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ class EdgeRepo
|
|||||||
|
|
||||||
public function remove(Edge $edge): void
|
public function remove(Edge $edge): void
|
||||||
{
|
{
|
||||||
DB::table("edges")
|
Database::make()->table("edges")
|
||||||
->where("source", $edge->source)
|
->where("source", $edge->source)
|
||||||
->where("target", $edge->target)
|
->where("target", $edge->target)
|
||||||
->where("sourceSchema", $edge->sourceSchema)
|
->where("sourceSchema", $edge->sourceSchema)
|
||||||
@@ -100,7 +100,7 @@ class EdgeRepo
|
|||||||
|
|
||||||
public function findLastEdgeRank(string $source, string $field): string
|
public function findLastEdgeRank(string $source, string $field): string
|
||||||
{
|
{
|
||||||
$data = DB::table("edges")
|
$data = Database::make()->table("edges")
|
||||||
->where("source", $source)
|
->where("source", $source)
|
||||||
->where("field", $field)
|
->where("field", $field)
|
||||||
->orderBy("rank", "desc")
|
->orderBy("rank", "desc")
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ namespace Lucent\File;
|
|||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Intervention\Image\ImageManagerStatic;
|
use Intervention\Image\ImageManagerStatic;
|
||||||
use Lucent\Channel\ChannelService;
|
use Lucent\Channel\ChannelService;
|
||||||
|
use Lucent\Database\Database;
|
||||||
use Lucent\LucentException;
|
use Lucent\LucentException;
|
||||||
use Lucent\Record\FileData as RecordFile;
|
use Lucent\Record\FileData as RecordFile;
|
||||||
use Lucent\Record\QueryRecord;
|
use Lucent\Record\QueryRecord;
|
||||||
@@ -129,7 +129,7 @@ class FileService
|
|||||||
private function checkDuplicate(string $schemaName, string $checksum, int $filesize): string
|
private function checkDuplicate(string $schemaName, string $checksum, int $filesize): string
|
||||||
{
|
{
|
||||||
|
|
||||||
$record = DB::table("records")
|
$record = Database::make()->table("records")
|
||||||
->where("schema", $schemaName)
|
->where("schema", $schemaName)
|
||||||
->where("_file->checksum", $checksum)
|
->where("_file->checksum", $checksum)
|
||||||
->where("_file->size", $filesize)
|
->where("_file->size", $filesize)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace Lucent\Query\DatabaseGraph;
|
namespace Lucent\Query\DatabaseGraph;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Lucent\Database\Database;
|
||||||
use Lucent\Query\QueryOptions;
|
use Lucent\Query\QueryOptions;
|
||||||
|
|
||||||
class PgsqlDatabaseGraph implements DatabaseGraph
|
class PgsqlDatabaseGraph implements DatabaseGraph
|
||||||
@@ -13,7 +14,7 @@ class PgsqlDatabaseGraph implements DatabaseGraph
|
|||||||
*/
|
*/
|
||||||
public function getChildren(array $ids, QueryOptions $options): array
|
public function getChildren(array $ids, QueryOptions $options): array
|
||||||
{
|
{
|
||||||
$subquery = DB::table('edges AS g')
|
$subquery = Database::make()->table('edges AS g')
|
||||||
->select(DB::raw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field, 1 as depth '))
|
->select(DB::raw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field, 1 as depth '))
|
||||||
->whereIn('source', $ids);
|
->whereIn('source', $ids);
|
||||||
|
|
||||||
@@ -23,14 +24,14 @@ class PgsqlDatabaseGraph implements DatabaseGraph
|
|||||||
|
|
||||||
$subquery->limit($options->childrenLimit)
|
$subquery->limit($options->childrenLimit)
|
||||||
->unionAll(
|
->unionAll(
|
||||||
DB::table(DB::raw("edges AS g, search_graph AS sg "))
|
Database::make()->table(DB::raw("edges AS g, search_graph AS sg "))
|
||||||
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth')
|
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth')
|
||||||
->whereRaw("g.source = sg.target")
|
->whereRaw("g.source = sg.target")
|
||||||
->where("depth", "<", $options->childrenDepth)
|
->where("depth", "<", $options->childrenDepth)
|
||||||
->orderBy("rank")
|
->orderBy("rank")
|
||||||
);
|
);
|
||||||
|
|
||||||
return DB::table('search_graph')
|
return Database::make()->table('search_graph')
|
||||||
// ->select(DB::raw("*, 1 as depth "))
|
// ->select(DB::raw("*, 1 as depth "))
|
||||||
->withRecursiveExpression('search_graph', $subquery)
|
->withRecursiveExpression('search_graph', $subquery)
|
||||||
->get()->toArray();
|
->get()->toArray();
|
||||||
@@ -41,19 +42,19 @@ class PgsqlDatabaseGraph implements DatabaseGraph
|
|||||||
*/
|
*/
|
||||||
public function getParents(array $ids, QueryOptions $options): array
|
public function getParents(array $ids, QueryOptions $options): array
|
||||||
{
|
{
|
||||||
$subquery = DB::table('edges AS g')
|
$subquery = Database::make()->table('edges AS g')
|
||||||
->select(DB::raw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field, 1 as depth '))
|
->select(DB::raw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field, 1 as depth '))
|
||||||
->limit($options->parentsLimit)
|
->limit($options->parentsLimit)
|
||||||
->whereIn('g.target', $ids)
|
->whereIn('g.target', $ids)
|
||||||
->unionAll(
|
->unionAll(
|
||||||
DB::table(DB::raw("edges AS g, search_graph AS sg "))
|
Database::make()->table(DB::raw("edges AS g, search_graph AS sg "))
|
||||||
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth')
|
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth')
|
||||||
->whereRaw("g.target = sg.source")
|
->whereRaw("g.target = sg.source")
|
||||||
->where("depth", "<", $options->parentsDepth)
|
->where("depth", "<", $options->parentsDepth)
|
||||||
->orderBy("rank")
|
->orderBy("rank")
|
||||||
);
|
);
|
||||||
|
|
||||||
return DB::table('search_graph')
|
return Database::make()->table('search_graph')
|
||||||
// ->select(DB::raw('sg.source,sg.target,sg.rank,sg."sourceSchema",sg."targetSchema",sg.field,sg.depth'))
|
// ->select(DB::raw('sg.source,sg.target,sg.rank,sg."sourceSchema",sg."targetSchema",sg.field,sg.depth'))
|
||||||
->withRecursiveExpression('search_graph', $subquery)
|
->withRecursiveExpression('search_graph', $subquery)
|
||||||
->get()->toArray();
|
->get()->toArray();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace Lucent\Query\DatabaseGraph;
|
namespace Lucent\Query\DatabaseGraph;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Lucent\Database\Database;
|
||||||
use Lucent\Query\QueryOptions;
|
use Lucent\Query\QueryOptions;
|
||||||
|
|
||||||
class SqliteDatabaseGraph implements DatabaseGraph
|
class SqliteDatabaseGraph implements DatabaseGraph
|
||||||
@@ -12,7 +13,7 @@ class SqliteDatabaseGraph implements DatabaseGraph
|
|||||||
*/
|
*/
|
||||||
public function getChildren(array $ids, QueryOptions $options): array
|
public function getChildren(array $ids, QueryOptions $options): array
|
||||||
{
|
{
|
||||||
$subquery = DB::table('edges AS g')
|
$subquery = Database::make()->table('edges AS g')
|
||||||
->select(DB::raw('g.source,g.target,g.rank,g.sourceSchema,g.targetSchema,g.field, 1 as depth '))
|
->select(DB::raw('g.source,g.target,g.rank,g.sourceSchema,g.targetSchema,g.field, 1 as depth '))
|
||||||
->whereIn('source', $ids);
|
->whereIn('source', $ids);
|
||||||
|
|
||||||
@@ -22,14 +23,14 @@ class SqliteDatabaseGraph implements DatabaseGraph
|
|||||||
|
|
||||||
$subquery->limit($options->childrenLimit)
|
$subquery->limit($options->childrenLimit)
|
||||||
->unionAll(
|
->unionAll(
|
||||||
DB::table(DB::raw("edges AS g, search_graph AS sg "))
|
Database::make()->table(DB::raw("edges AS g, search_graph AS sg "))
|
||||||
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth')
|
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth')
|
||||||
->whereRaw("g.source = sg.target")
|
->whereRaw("g.source = sg.target")
|
||||||
->where("depth", "<", $options->childrenDepth)
|
->where("depth", "<", $options->childrenDepth)
|
||||||
->orderBy("rank")
|
->orderBy("rank")
|
||||||
);
|
);
|
||||||
|
|
||||||
return DB::table('search_graph')
|
return Database::make()->table('search_graph')
|
||||||
// ->select(DB::raw("*, 1 as depth "))
|
// ->select(DB::raw("*, 1 as depth "))
|
||||||
->withRecursiveExpression('search_graph', $subquery)
|
->withRecursiveExpression('search_graph', $subquery)
|
||||||
->get()->toArray();
|
->get()->toArray();
|
||||||
@@ -40,19 +41,19 @@ class SqliteDatabaseGraph implements DatabaseGraph
|
|||||||
*/
|
*/
|
||||||
public function getParents(array $ids, QueryOptions $options): array
|
public function getParents(array $ids, QueryOptions $options): array
|
||||||
{
|
{
|
||||||
$subquery = DB::table('edges AS g')
|
$subquery = Database::make()->table('edges AS g')
|
||||||
->select(DB::raw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field, 1 as depth '))
|
->select(DB::raw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field, 1 as depth '))
|
||||||
->limit($options->parentsLimit)
|
->limit($options->parentsLimit)
|
||||||
->whereIn('g.target', $ids)
|
->whereIn('g.target', $ids)
|
||||||
->unionAll(
|
->unionAll(
|
||||||
DB::table(DB::raw("edges AS g, search_graph AS sg "))
|
Database::make()->table(DB::raw("edges AS g, search_graph AS sg "))
|
||||||
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth')
|
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth')
|
||||||
->whereRaw("g.target = sg.source")
|
->whereRaw("g.target = sg.source")
|
||||||
->where("depth", "<", $options->parentsDepth)
|
->where("depth", "<", $options->parentsDepth)
|
||||||
->orderBy("rank")
|
->orderBy("rank")
|
||||||
);
|
);
|
||||||
|
|
||||||
return DB::table('search_graph')
|
return Database::make()->table('search_graph')
|
||||||
// ->select(DB::raw('sg.source,sg.target,sg.rank,sg."sourceSchema",sg."targetSchema",sg.field,sg.depth'))
|
// ->select(DB::raw('sg.source,sg.target,sg.rank,sg."sourceSchema",sg."targetSchema",sg.field,sg.depth'))
|
||||||
->withRecursiveExpression('search_graph', $subquery)
|
->withRecursiveExpression('search_graph', $subquery)
|
||||||
->get()->toArray();
|
->get()->toArray();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ namespace Lucent\Query;
|
|||||||
|
|
||||||
use Illuminate\Contracts\Foundation\Application;
|
use Illuminate\Contracts\Foundation\Application;
|
||||||
use Illuminate\Database\Query\Builder;
|
use Illuminate\Database\Query\Builder;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Lucent\Database\Database;
|
||||||
use Lucent\Query\BuilderConverter\BuilderConverter;
|
use Lucent\Query\BuilderConverter\BuilderConverter;
|
||||||
use Lucent\Query\Filter\AndFilter;
|
use Lucent\Query\Filter\AndFilter;
|
||||||
use Lucent\Query\Filter\Argument;
|
use Lucent\Query\Filter\Argument;
|
||||||
@@ -58,7 +58,7 @@ final class FilterParser
|
|||||||
}
|
}
|
||||||
|
|
||||||
$targetIds = collect($graph->records)->pluck("id");
|
$targetIds = collect($graph->records)->pluck("id");
|
||||||
$sourceIds = DB::table("edges")->whereIn("target", $targetIds)->where("field", $k)->get()->pluck("source");
|
$sourceIds = Database::make()->table("edges")->whereIn("target", $targetIds)->where("field", $k)->get()->pluck("source");
|
||||||
return array_merge($c, $sourceIds->toArray());
|
return array_merge($c, $sourceIds->toArray());
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -3,7 +3,7 @@
|
|||||||
namespace Lucent\Query;
|
namespace Lucent\Query;
|
||||||
|
|
||||||
use Illuminate\Database\Query\Builder;
|
use Illuminate\Database\Query\Builder;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Lucent\Database\Database;
|
||||||
use Lucent\Edge\Edge;
|
use Lucent\Edge\Edge;
|
||||||
use Lucent\Primitive\Collection;
|
use Lucent\Primitive\Collection;
|
||||||
use Lucent\Query\DatabaseGraph\DatabaseGraph;
|
use Lucent\Query\DatabaseGraph\DatabaseGraph;
|
||||||
@@ -67,7 +67,7 @@ final class Query
|
|||||||
$edgesIds = collect($resultParentSourceTargetIds)->merge($resultChildrenEdgesTargetIds)->unique()->values()->toArray();
|
$edgesIds = collect($resultParentSourceTargetIds)->merge($resultChildrenEdgesTargetIds)->unique()->values()->toArray();
|
||||||
$edgeRecords = [];
|
$edgeRecords = [];
|
||||||
if (!empty($edgesIds)) {
|
if (!empty($edgesIds)) {
|
||||||
$edgeRecords = DB::table('records')
|
$edgeRecords = Database::make()->table('records')
|
||||||
->whereIn("id", $edgesIds)
|
->whereIn("id", $edgesIds)
|
||||||
->whereIn("status", $this->options->status)
|
->whereIn("status", $this->options->status)
|
||||||
->get()->toArray();
|
->get()->toArray();
|
||||||
@@ -142,7 +142,7 @@ final class Query
|
|||||||
|
|
||||||
private function mainQuery(): array
|
private function mainQuery(): array
|
||||||
{
|
{
|
||||||
$query = DB::table("records");
|
$query = Database::make()->table("records");
|
||||||
$query = $this->parseFilters($query);
|
$query = $this->parseFilters($query);
|
||||||
$query = $this->findNotLinked($query);
|
$query = $this->findNotLinked($query);
|
||||||
|
|
||||||
@@ -189,7 +189,7 @@ final class Query
|
|||||||
function runWithCount(): Graph
|
function runWithCount(): Graph
|
||||||
{
|
{
|
||||||
|
|
||||||
$query = DB::table("records");
|
$query = Database::make()->table("records");
|
||||||
$query = $this->parseFilters($query);
|
$query = $this->parseFilters($query);
|
||||||
$query = $this->findNotLinked($query);
|
$query = $this->findNotLinked($query);
|
||||||
$graph = $this->run();
|
$graph = $this->run();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Lucent\Record;
|
namespace Lucent\Record;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\DB;
|
use Lucent\Database\Database;
|
||||||
|
|
||||||
class RecordRepo
|
class RecordRepo
|
||||||
{
|
{
|
||||||
@@ -14,7 +14,7 @@ class RecordRepo
|
|||||||
{
|
{
|
||||||
$recordToDB = $record->toDB();
|
$recordToDB = $record->toDB();
|
||||||
|
|
||||||
DB::table("records")->insert($recordToDB);
|
Database::make()->table("records")->insert($recordToDB);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ class RecordRepo
|
|||||||
*/
|
*/
|
||||||
public static function updateStatusBulk(Status $status, array $ids): void
|
public static function updateStatusBulk(Status $status, array $ids): void
|
||||||
{
|
{
|
||||||
DB::table("records")->whereIn("id", $ids)->update([
|
Database::make()->table("records")->whereIn("id", $ids)->update([
|
||||||
'status' => $status->value
|
'status' => $status->value
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ class RecordRepo
|
|||||||
public static function update(Record $record): void
|
public static function update(Record $record): void
|
||||||
{
|
{
|
||||||
$recordToDB = $record->toDB();
|
$recordToDB = $record->toDB();
|
||||||
DB::table("records")->where("id", $record->id)->update($recordToDB);
|
Database::make()->table("records")->where("id", $record->id)->update($recordToDB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -43,17 +43,17 @@ class RecordRepo
|
|||||||
): void
|
): void
|
||||||
{
|
{
|
||||||
|
|
||||||
DB::table("records")->whereIn("id", $ids)->delete();
|
Database::make()->table("records")->whereIn("id", $ids)->delete();
|
||||||
DB::table("edges")->whereIn("source", $ids)->delete();
|
Database::make()->table("edges")->whereIn("source", $ids)->delete();
|
||||||
DB::table("edges")->whereIn("target", $ids)->delete();
|
Database::make()->table("edges")->whereIn("target", $ids)->delete();
|
||||||
DB::table("revisions")->whereIn("recordId", $ids)->delete();
|
Database::make()->table("revisions")->whereIn("recordId", $ids)->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteTrashedBySchema(
|
public function deleteTrashedBySchema(
|
||||||
string $schemaName,
|
string $schemaName,
|
||||||
): void
|
): void
|
||||||
{
|
{
|
||||||
$ids = DB::table("records")
|
$ids = Database::make()->table("records")
|
||||||
->where("schema", $schemaName)
|
->where("schema", $schemaName)
|
||||||
->where("status", Status::TRASHED->value)
|
->where("status", Status::TRASHED->value)
|
||||||
->get()->pluck("id")->toArray();
|
->get()->pluck("id")->toArray();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Lucent\Revision;
|
namespace Lucent\Revision;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\DB;
|
use Lucent\Database\Database;
|
||||||
use Lucent\Edge\Edge;
|
use Lucent\Edge\Edge;
|
||||||
use Lucent\Primitive\Collection;
|
use Lucent\Primitive\Collection;
|
||||||
use Lucent\Record\FileData;
|
use Lucent\Record\FileData;
|
||||||
@@ -19,7 +19,7 @@ class RevisionRepo
|
|||||||
public function create(Revision $revision): string
|
public function create(Revision $revision): string
|
||||||
{
|
{
|
||||||
$revisionDB = $this->toDB($revision);
|
$revisionDB = $this->toDB($revision);
|
||||||
DB::table($this->table)->insert($revisionDB);
|
Database::make()->table($this->table)->insert($revisionDB);
|
||||||
return $revision->id;
|
return $revision->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ class RevisionRepo
|
|||||||
**/
|
**/
|
||||||
public function getByRecordId(string $rid): Collection
|
public function getByRecordId(string $rid): Collection
|
||||||
{
|
{
|
||||||
$revisions = DB::table($this->table)
|
$revisions = Database::make()->table($this->table)
|
||||||
->where("recordId", $rid)
|
->where("recordId", $rid)
|
||||||
->get()
|
->get()
|
||||||
->map([$this, 'fromDB'])
|
->map([$this, 'fromDB'])
|
||||||
@@ -41,7 +41,7 @@ class RevisionRepo
|
|||||||
|
|
||||||
public function cleanupRecord(string $rid, int $numKeep): void
|
public function cleanupRecord(string $rid, int $numKeep): void
|
||||||
{
|
{
|
||||||
$revisionIds = DB::table($this->table)
|
$revisionIds = Database::make()->table($this->table)
|
||||||
->where("recordId", $rid)
|
->where("recordId", $rid)
|
||||||
->orderBy("_sys->version", "desc")
|
->orderBy("_sys->version", "desc")
|
||||||
->limit(100)
|
->limit(100)
|
||||||
@@ -49,7 +49,7 @@ class RevisionRepo
|
|||||||
->get()
|
->get()
|
||||||
->pluck("id");
|
->pluck("id");
|
||||||
|
|
||||||
DB::table($this->table)
|
Database::make()->table($this->table)
|
||||||
->whereIn("id", $revisionIds)
|
->whereIn("id", $revisionIds)
|
||||||
->delete();
|
->delete();
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ class RevisionRepo
|
|||||||
public function getByRecordIdAndVersion(string $rid, int $version): Option
|
public function getByRecordIdAndVersion(string $rid, int $version): Option
|
||||||
{
|
{
|
||||||
|
|
||||||
$res = DB::table($this->table)
|
$res = Database::make()->table($this->table)
|
||||||
->where("recordId", $rid)
|
->where("recordId", $rid)
|
||||||
->where('_sys->version', $version)->first();
|
->where('_sys->version', $version)->first();
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace Lucent\Setup\Step;
|
namespace Lucent\Setup\Step;
|
||||||
|
|
||||||
use Illuminate\Database\QueryException;
|
use Illuminate\Database\QueryException;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Lucent\Database\Database;
|
||||||
use Lucent\Setup\Data\SetupStep;
|
use Lucent\Setup\Data\SetupStep;
|
||||||
|
|
||||||
class DatabaseSetupStep implements IStep
|
class DatabaseSetupStep implements IStep
|
||||||
@@ -13,21 +13,18 @@ class DatabaseSetupStep implements IStep
|
|||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$name = "Database Connection";
|
$name = "Database Connection";
|
||||||
|
|
||||||
|
$databaseConnectionName = config("lucent.database");
|
||||||
|
|
||||||
|
$databaseConfig = config('database.connections.'.$databaseConnectionName);
|
||||||
$databaseConfig = config('database.connections.lucentdb');
|
if (empty($databaseConfig)) {
|
||||||
if(empty($databaseConfig)) {
|
|
||||||
$instructions = <<<EOD
|
$instructions = <<<EOD
|
||||||
# You need to setup a database connection for lucentdb in database.php config. You can choose either sqlite or pgsql
|
# You need to setup a database connection for $databaseConnectionName in database.php config. You can choose either sqlite or pgsql
|
||||||
# example:
|
# example:
|
||||||
|
|
||||||
'connections' => [
|
'connections' => [
|
||||||
'lucentdb' => [
|
'$databaseConnectionName' => [
|
||||||
'driver' => 'sqlite',
|
'driver' => 'sqlite',
|
||||||
'url' => env('LUCENT_DATABASE_URL'),
|
'url' => env('LUCENT_DATABASE_URL'),
|
||||||
'database' => env('LUCENT_DB_DATABASE', database_path('database.sqlite')),
|
'database' => env('LUCENT_DB_DATABASE', database_path('database.sqlite')),
|
||||||
@@ -39,8 +36,8 @@ EOD;
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DB::connection("lucentdb")->table("records")->get();
|
Database::make()->table("records")->get();
|
||||||
}catch (QueryException $e) {
|
} catch (QueryException $e) {
|
||||||
$instructions = <<<EOD
|
$instructions = <<<EOD
|
||||||
# Make sure you run:
|
# Make sure you run:
|
||||||
php artisan lucent:setup-db
|
php artisan lucent:setup-db
|
||||||
|
|||||||
Reference in New Issue
Block a user