@bejibun/database 0.1.1 → 0.1.12

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 CHANGED
@@ -3,6 +3,39 @@ All notable changes to this project will be documented in this file.
3
3
 
4
4
  ---
5
5
 
6
+ ## [v0.1.12](https://github.com/crenata/bejibun-database/compare/v0.1.11...v0.1.12) - 2025-10-25
7
+
8
+ ### 🩹 Fixes
9
+ - Fix `make:migration` counter undefined
10
+
11
+ ### 📖 Changes
12
+ What's New :
13
+ - Adding `make:seeder` Create a new seeder file
14
+
15
+ ### ❤️Contributors
16
+ - Havea Crenata ([@crenata](https://github.com/crenata))
17
+ - Ghulje ([@ghulje](https://github.com/ghulje))
18
+
19
+ **Full Changelog**: https://github.com/crenata/bejibun-database/blob/master/CHANGELOG.md
20
+
21
+ ---
22
+
23
+ ## [v0.1.11](https://github.com/crenata/bejibun-database/compare/v0.1.1...v0.1.11) - 2025-10-25
24
+
25
+ ### 🩹 Fixes
26
+
27
+ ### 📖 Changes
28
+ What's New :
29
+ - Adding `make:migration` Create a new migration file
30
+
31
+ ### ❤️Contributors
32
+ - Havea Crenata ([@crenata](https://github.com/crenata))
33
+ - Ghulje ([@ghulje](https://github.com/ghulje))
34
+
35
+ **Full Changelog**: https://github.com/crenata/bejibun-database/blob/master/CHANGELOG.md
36
+
37
+ ---
38
+
6
39
  ## [v0.1.1](https://github.com/crenata/bejibun-database/compare/v0.1.0...v0.1.1) - 2025-10-22
7
40
 
8
41
  ### 🩹 Fixes
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
  ![GitHub top language](https://img.shields.io/github/languages/top/crenata/bejibun-database)
4
6
  ![GitHub all releases](https://img.shields.io/github/downloads/crenata/bejibun-database/total)
5
7
  ![GitHub issues](https://img.shields.io/github/issues/crenata/bejibun-database)
@@ -25,7 +27,11 @@ bun ace install @bejibun/database
25
27
  ```
26
28
 
27
29
  ### Configuration
28
- Add `database.ts` inside config directory on your project
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
@@ -71,7 +77,7 @@ If you find this project helpful and want to support it, you can donate via PayP
71
77
 
72
78
  Or if you are prefer using crypto :
73
79
 
74
- | EVM | Solana |
75
- | --- | ------ |
80
+ | EVM | Solana |
81
+ | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
76
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" /> |
77
- | 0xdABe8750061410D35cE52EB2a418c8cB004788B3 | GAnoyvy9p3QFyxikWDh9hA3fmSk2uiPLNWyQ579cckMn |
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 { defineValue, 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 = defineValue(parseInt(latest), 0);
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,27 @@
1
+ export default class MakeSeederCommand {
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 { defineValue, isEmpty } from "@bejibun/utils";
4
+ import Luxon from "@bejibun/utils/facades/Luxon";
5
+ import path from "path";
6
+ export default class MakeSeederCommand {
7
+ /**
8
+ * The name and signature of the console command.
9
+ *
10
+ * @var $signature string
11
+ */
12
+ $signature = "make:seeder";
13
+ /**
14
+ * The console command description.
15
+ *
16
+ * @var $description string
17
+ */
18
+ $description = "Create a new seeder 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 seeder 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 seedersDirectory = "seeders";
40
+ const seedersPath = path.resolve(__dirname, `../../database/${seedersDirectory}`);
41
+ const seeders = Array.from(new Bun.Glob("**/*").scanSync({
42
+ cwd: seedersPath
43
+ })).filter(value => (/\.(m?js|ts)$/.test(value) &&
44
+ !value.endsWith(".d.ts")));
45
+ const template = seeders.find(value => value.includes("seeder_template"));
46
+ if (isEmpty(template)) {
47
+ Logger.setContext("APP").error("Whoops, something went wrong, the seeder 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(seedersDirectory)
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 = defineValue(parseInt(latest), 0);
63
+ const destination = `${seedersDirectory}/${now}_${String(counter + 1).padStart(6, "0")}_${file}.ts`;
64
+ await Bun.write(App.Path.databasePath(destination), await Bun.file(path.resolve(seedersPath, template)).text());
65
+ Logger.setContext("APP").info(`Seeder [database/${destination}] created successfully.`);
66
+ }
67
+ }
@@ -0,0 +1,3 @@
1
+ import type { Knex } from "knex";
2
+ export declare function up(knex: Knex): Knex.SchemaBuilder;
3
+ export declare function down(knex: Knex): Knex.SchemaBuilder;
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ import type { Knex } from "knex";
2
+ export declare function seed(knex: Knex): Promise<void>;
@@ -0,0 +1,3 @@
1
+ export async function seed(knex) {
2
+ // Your code goes here...
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bejibun/database",
3
- "version": "0.1.1",
3
+ "version": "0.1.12",
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.18",
40
- "@bejibun/utils": "^0.1.14",
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"