@bejibun/database 0.1.0 → 0.1.11
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/CHANGELOG.md +17 -1
- package/README.md +12 -35
- package/commands/make/MakeMigrationCommand.d.ts +27 -0
- package/commands/make/MakeMigrationCommand.js +67 -0
- package/database/migrations/migration_template.d.ts +3 -0
- package/database/migrations/migration_template.js +10 -0
- package/database/seeders/seeder_template.d.ts +2 -0
- package/database/seeders/seeder_template.js +3 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,23 @@ All notable changes to this project will be documented in this file.
|
|
|
3
3
|
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
## [v0.1.
|
|
6
|
+
## [v0.1.11](https://github.com/crenata/bejibun-database/compare/v0.1.1...v0.1.11) - 2025-10-25
|
|
7
|
+
|
|
8
|
+
### 🩹 Fixes
|
|
9
|
+
|
|
10
|
+
### 📖 Changes
|
|
11
|
+
What's New :
|
|
12
|
+
- Adding `make:migration` Create a new migration file
|
|
13
|
+
|
|
14
|
+
### ❤️Contributors
|
|
15
|
+
- Havea Crenata ([@crenata](https://github.com/crenata))
|
|
16
|
+
- Ghulje ([@ghulje](https://github.com/ghulje))
|
|
17
|
+
|
|
18
|
+
**Full Changelog**: https://github.com/crenata/bejibun-database/blob/master/CHANGELOG.md
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## [v0.1.1](https://github.com/crenata/bejibun-database/compare/v0.1.0...v0.1.1) - 2025-10-22
|
|
7
23
|
|
|
8
24
|
### 🩹 Fixes
|
|
9
25
|
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
+
<img src="https://github.com/crenata/bejibun/blob/master/public/images/bejibun.png?raw=true" width="150" alt="Bejibun" />
|
|
4
|
+
|
|
3
5
|

|
|
4
6
|

|
|
5
7
|

|
|
@@ -9,7 +11,7 @@
|
|
|
9
11
|
</div>
|
|
10
12
|
|
|
11
13
|
# Database for Bejibun
|
|
12
|
-
Database
|
|
14
|
+
Database for Bejibun Framework.
|
|
13
15
|
|
|
14
16
|
## Usage
|
|
15
17
|
|
|
@@ -25,7 +27,11 @@ bun ace install @bejibun/database
|
|
|
25
27
|
```
|
|
26
28
|
|
|
27
29
|
### Configuration
|
|
28
|
-
|
|
30
|
+
The configuration file automatically executed if you are using `ace`.
|
|
31
|
+
|
|
32
|
+
Or
|
|
33
|
+
|
|
34
|
+
Add `database.ts` inside config directory on your project if doesn't exist.
|
|
29
35
|
|
|
30
36
|
```bash
|
|
31
37
|
config/database.ts
|
|
@@ -55,38 +61,9 @@ You can pass the value with environment variables.
|
|
|
55
61
|
How to use tha package.
|
|
56
62
|
|
|
57
63
|
```ts
|
|
58
|
-
import type {DatabasePipeline} from "@bejibun/database/types";
|
|
59
|
-
import BaseController from "@bejibun/core/bases/BaseController";
|
|
60
|
-
import Logger from "@bejibun/logger";
|
|
61
64
|
import Database from "@bejibun/database";
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
public async database(request: Bun.BunRequest): Promise<Response> {
|
|
65
|
-
await Database.set("database", {hello: "world"});
|
|
66
|
-
const database = await Database.get("database");
|
|
67
|
-
|
|
68
|
-
await Database.connection("local").set("connection", "This is using custom connection.");
|
|
69
|
-
const connection = await Database.connection("local").get("connection");
|
|
70
|
-
|
|
71
|
-
const pipeline = await Database.pipeline((pipe: DatabasePipeline) => {
|
|
72
|
-
pipe.set("database-pipeline-1", "This is database pipeline 1");
|
|
73
|
-
pipe.set("database-pipeline-2", "This is database pipeline 2");
|
|
74
|
-
|
|
75
|
-
pipe.get("database-pipeline-1");
|
|
76
|
-
pipe.get("database-pipeline-2");
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const subscriber = await Database.subscribe("database-subscribe", (message: string, channel: string) => {
|
|
80
|
-
Logger.setContext(channel).debug(message);
|
|
81
|
-
});
|
|
82
|
-
await Database.publish("database-subscribe", "Hai database subscriber!");
|
|
83
|
-
setTimeout(async () => {
|
|
84
|
-
await subscriber.unsubscribe();
|
|
85
|
-
}, 500);
|
|
86
|
-
|
|
87
|
-
return super.response.setData({database, connection, pipeline}).send();
|
|
88
|
-
}
|
|
89
|
-
}
|
|
66
|
+
Database.knex();
|
|
90
67
|
```
|
|
91
68
|
|
|
92
69
|
## Contributors
|
|
@@ -100,7 +77,7 @@ If you find this project helpful and want to support it, you can donate via PayP
|
|
|
100
77
|
|
|
101
78
|
Or if you are prefer using crypto :
|
|
102
79
|
|
|
103
|
-
| EVM
|
|
104
|
-
|
|
|
80
|
+
| EVM | Solana |
|
|
81
|
+
| ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
|
|
105
82
|
| <img src="https://github.com/crenata/bejibun/blob/master/public/images/EVM.png?raw=true" width="150" /> | <img src="https://github.com/crenata/bejibun/blob/master/public/images/SOL.png?raw=true" width="150" /> |
|
|
106
|
-
| 0xdABe8750061410D35cE52EB2a418c8cB004788B3
|
|
83
|
+
| 0xdABe8750061410D35cE52EB2a418c8cB004788B3 | GAnoyvy9p3QFyxikWDh9hA3fmSk2uiPLNWyQ579cckMn |
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default class MakeMigrationCommand {
|
|
2
|
+
/**
|
|
3
|
+
* The name and signature of the console command.
|
|
4
|
+
*
|
|
5
|
+
* @var $signature string
|
|
6
|
+
*/
|
|
7
|
+
protected $signature: string;
|
|
8
|
+
/**
|
|
9
|
+
* The console command description.
|
|
10
|
+
*
|
|
11
|
+
* @var $description string
|
|
12
|
+
*/
|
|
13
|
+
protected $description: string;
|
|
14
|
+
/**
|
|
15
|
+
* The options or optional flag of the console command.
|
|
16
|
+
*
|
|
17
|
+
* @var $options Array<Array<any>>
|
|
18
|
+
*/
|
|
19
|
+
protected $options: Array<Array<any>>;
|
|
20
|
+
/**
|
|
21
|
+
* The arguments of the console command.
|
|
22
|
+
*
|
|
23
|
+
* @var $arguments Array<Array<string>>
|
|
24
|
+
*/
|
|
25
|
+
protected $arguments: Array<Array<string>>;
|
|
26
|
+
handle(options: any, args: Array<string>): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import App from "@bejibun/app";
|
|
2
|
+
import Logger from "@bejibun/logger";
|
|
3
|
+
import { isEmpty } from "@bejibun/utils";
|
|
4
|
+
import Luxon from "@bejibun/utils/facades/Luxon";
|
|
5
|
+
import path from "path";
|
|
6
|
+
export default class MakeMigrationCommand {
|
|
7
|
+
/**
|
|
8
|
+
* The name and signature of the console command.
|
|
9
|
+
*
|
|
10
|
+
* @var $signature string
|
|
11
|
+
*/
|
|
12
|
+
$signature = "make:migration";
|
|
13
|
+
/**
|
|
14
|
+
* The console command description.
|
|
15
|
+
*
|
|
16
|
+
* @var $description string
|
|
17
|
+
*/
|
|
18
|
+
$description = "Create a new migration file";
|
|
19
|
+
/**
|
|
20
|
+
* The options or optional flag of the console command.
|
|
21
|
+
*
|
|
22
|
+
* @var $options Array<Array<any>>
|
|
23
|
+
*/
|
|
24
|
+
$options = [];
|
|
25
|
+
/**
|
|
26
|
+
* The arguments of the console command.
|
|
27
|
+
*
|
|
28
|
+
* @var $arguments Array<Array<string>>
|
|
29
|
+
*/
|
|
30
|
+
$arguments = [
|
|
31
|
+
["<file>", "The name of the migration file"]
|
|
32
|
+
];
|
|
33
|
+
async handle(options, args) {
|
|
34
|
+
if (isEmpty(args)) {
|
|
35
|
+
Logger.setContext("APP").error("There is no filename provided.");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const file = args[0];
|
|
39
|
+
const migrationsDirectory = "migrations";
|
|
40
|
+
const migrationsPath = path.resolve(__dirname, `../../database/${migrationsDirectory}`);
|
|
41
|
+
const migrations = Array.from(new Bun.Glob("**/*").scanSync({
|
|
42
|
+
cwd: migrationsPath
|
|
43
|
+
})).filter(value => (/\.(m?js|ts)$/.test(value) &&
|
|
44
|
+
!value.endsWith(".d.ts")));
|
|
45
|
+
const template = migrations.find(value => value.includes("migration_template"));
|
|
46
|
+
if (isEmpty(template)) {
|
|
47
|
+
Logger.setContext("APP").error("Whoops, something went wrong, the migration template not found.");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const now = Luxon.datetime.now().toFormat("yyyyMMdd");
|
|
51
|
+
const latest = Array.from(new Bun.Glob("**/*").scanSync({
|
|
52
|
+
cwd: App.Path.databasePath(migrationsDirectory)
|
|
53
|
+
})).map((value) => {
|
|
54
|
+
const split = value.split("_").slice(0, 2);
|
|
55
|
+
return {
|
|
56
|
+
date: split[0],
|
|
57
|
+
count: split[1]
|
|
58
|
+
};
|
|
59
|
+
}).filter((value) => {
|
|
60
|
+
return value.date === now;
|
|
61
|
+
}).map((value) => value.count).sort().reverse()[0];
|
|
62
|
+
const counter = parseInt(latest);
|
|
63
|
+
const destination = `${migrationsDirectory}/${now}_${String(counter + 1).padStart(6, "0")}_${file}.ts`;
|
|
64
|
+
await Bun.write(App.Path.databasePath(destination), await Bun.file(path.resolve(migrationsPath, template)).text());
|
|
65
|
+
Logger.setContext("APP").info(`Migration [database/${destination}] created successfully.`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function up(knex) {
|
|
2
|
+
return knex.schema.createTable("tests", (table) => {
|
|
3
|
+
table.bigIncrements("id");
|
|
4
|
+
table.timestamps(true, true);
|
|
5
|
+
table.timestamp("deleted_at");
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
export function down(knex) {
|
|
9
|
+
return knex.schema.dropTable("tests");
|
|
10
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bejibun/database",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"author": "Havea Crenata <havea.crenata@gmail.com>",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"types": "index.d.ts",
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@bejibun/app": "^0.1.19",
|
|
39
|
-
"@bejibun/logger": "^0.1.
|
|
40
|
-
"@bejibun/utils": "^0.1.
|
|
39
|
+
"@bejibun/logger": "^0.1.19",
|
|
40
|
+
"@bejibun/utils": "^0.1.16",
|
|
41
41
|
"knex": "^3.1.0",
|
|
42
42
|
"ora": "^9.0.0",
|
|
43
43
|
"pg": "^8.16.3"
|