create-phoenixjs 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/template/config/database.ts +13 -1
- package/template/database/migrations/2024_01_01_000000_create_test_users_cli_table.ts +16 -0
- package/template/database/migrations/20260108164611_TestCliMigration.ts +16 -0
- package/template/database/migrations/2026_01_08_16_46_11_CreateTestMigrationsTable.ts +21 -0
- package/template/framework/cli/artisan.ts +12 -0
- package/template/framework/database/DatabaseManager.ts +133 -0
- package/template/framework/database/connection/Connection.ts +71 -0
- package/template/framework/database/connection/ConnectionFactory.ts +30 -0
- package/template/framework/database/connection/PostgresConnection.ts +159 -0
- package/template/framework/database/console/MakeMigrationCommand.ts +58 -0
- package/template/framework/database/console/MigrateCommand.ts +32 -0
- package/template/framework/database/console/MigrateResetCommand.ts +31 -0
- package/template/framework/database/console/MigrateRollbackCommand.ts +31 -0
- package/template/framework/database/console/MigrateStatusCommand.ts +38 -0
- package/template/framework/database/migrations/DatabaseMigrationRepository.ts +122 -0
- package/template/framework/database/migrations/Migration.ts +5 -0
- package/template/framework/database/migrations/MigrationRepository.ts +46 -0
- package/template/framework/database/migrations/Migrator.ts +249 -0
- package/template/framework/database/migrations/index.ts +4 -0
- package/template/framework/database/orm/BelongsTo.ts +246 -0
- package/template/framework/database/orm/BelongsToMany.ts +570 -0
- package/template/framework/database/orm/Builder.ts +160 -0
- package/template/framework/database/orm/EagerLoadingBuilder.ts +324 -0
- package/template/framework/database/orm/HasMany.ts +303 -0
- package/template/framework/database/orm/HasManyThrough.ts +282 -0
- package/template/framework/database/orm/HasOne.ts +201 -0
- package/template/framework/database/orm/HasOneThrough.ts +281 -0
- package/template/framework/database/orm/Model.ts +1766 -0
- package/template/framework/database/orm/Relation.ts +342 -0
- package/template/framework/database/orm/Scope.ts +14 -0
- package/template/framework/database/orm/SoftDeletes.ts +160 -0
- package/template/framework/database/orm/index.ts +54 -0
- package/template/framework/database/orm/scopes/SoftDeletingScope.ts +58 -0
- package/template/framework/database/pagination/LengthAwarePaginator.ts +55 -0
- package/template/framework/database/pagination/Paginator.ts +110 -0
- package/template/framework/database/pagination/index.ts +2 -0
- package/template/framework/database/query/Builder.ts +918 -0
- package/template/framework/database/query/DB.ts +139 -0
- package/template/framework/database/query/grammars/Grammar.ts +430 -0
- package/template/framework/database/query/grammars/PostgresGrammar.ts +224 -0
- package/template/framework/database/query/grammars/index.ts +6 -0
- package/template/framework/database/query/index.ts +8 -0
- package/template/framework/database/query/types.ts +196 -0
- package/template/framework/database/schema/Blueprint.ts +478 -0
- package/template/framework/database/schema/Schema.ts +149 -0
- package/template/framework/database/schema/SchemaBuilder.ts +152 -0
- package/template/framework/database/schema/grammars/PostgresSchemaGrammar.ts +293 -0
- package/template/framework/database/schema/grammars/index.ts +5 -0
- package/template/framework/database/schema/index.ts +9 -0
- package/template/package.json +4 -1
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PhoenixJS ORM - Paginator
|
|
3
|
+
*
|
|
4
|
+
* Base class for pagination.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export class Paginator<T> {
|
|
8
|
+
/**
|
|
9
|
+
* The items for the current page.
|
|
10
|
+
*/
|
|
11
|
+
public items: T[];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The number of items per page.
|
|
15
|
+
*/
|
|
16
|
+
public perPage: number;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The current page number.
|
|
20
|
+
*/
|
|
21
|
+
public currentPage: number;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Determine if there are more items in the data source.
|
|
25
|
+
*/
|
|
26
|
+
public hasMore: boolean;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The base path for paginator links.
|
|
30
|
+
*/
|
|
31
|
+
public path: string = '/';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The query string parameters for paginator links.
|
|
35
|
+
*/
|
|
36
|
+
public query: Record<string, string> = {};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create a new Paginator instance.
|
|
40
|
+
*/
|
|
41
|
+
constructor(
|
|
42
|
+
items: T[],
|
|
43
|
+
perPage: number,
|
|
44
|
+
currentPage: number,
|
|
45
|
+
options: { path?: string; query?: Record<string, string>; hasMore?: boolean } = {}
|
|
46
|
+
) {
|
|
47
|
+
this.items = items;
|
|
48
|
+
this.perPage = perPage;
|
|
49
|
+
this.currentPage = currentPage;
|
|
50
|
+
this.path = options.path || this.path;
|
|
51
|
+
this.query = options.query || this.query;
|
|
52
|
+
this.hasMore = options.hasMore ?? items.length > 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Get the URL for the next page.
|
|
57
|
+
*/
|
|
58
|
+
public nextPageUrl(): string | null {
|
|
59
|
+
if (this.hasMore) {
|
|
60
|
+
return this.url(this.currentPage + 1);
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Get the URL for the previous page.
|
|
67
|
+
*/
|
|
68
|
+
public previousPageUrl(): string | null {
|
|
69
|
+
if (this.currentPage > 1) {
|
|
70
|
+
return this.url(this.currentPage - 1);
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Get the URL for a given page number.
|
|
77
|
+
*/
|
|
78
|
+
public url(page: number): string {
|
|
79
|
+
if (page <= 0) page = 1;
|
|
80
|
+
|
|
81
|
+
const queryParams = new URLSearchParams(this.query);
|
|
82
|
+
queryParams.set('page', page.toString());
|
|
83
|
+
|
|
84
|
+
return `${this.path}?${queryParams.toString()}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Get the instance as an array (returns items).
|
|
89
|
+
*/
|
|
90
|
+
public toArray(): T[] {
|
|
91
|
+
return this.items;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Convert the instance to JSON.
|
|
96
|
+
*/
|
|
97
|
+
public toJSON(): Record<string, unknown> {
|
|
98
|
+
return {
|
|
99
|
+
data: this.items,
|
|
100
|
+
current_page: this.currentPage,
|
|
101
|
+
per_page: this.perPage,
|
|
102
|
+
first_page_url: this.url(1),
|
|
103
|
+
next_page_url: this.nextPageUrl(),
|
|
104
|
+
prev_page_url: this.previousPageUrl(),
|
|
105
|
+
path: this.path,
|
|
106
|
+
from: (this.currentPage - 1) * this.perPage + 1,
|
|
107
|
+
to: (this.currentPage - 1) * this.perPage + this.items.length,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|