@stacksjs/database 0.39.0 → 0.40.0

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.
@@ -1,2 +1,13 @@
1
- declare function factory(): void;
2
- export { factory };
1
+ declare class Factory {
2
+ private factory;
3
+ private noOfItems;
4
+ private items;
5
+ private columns;
6
+ constructor(factory: string);
7
+ define(params: any): this;
8
+ count(count?: number): this;
9
+ make(count?: number): Promise<any>;
10
+ create(count?: number): Promise<any>;
11
+ intiateColumns(): void;
12
+ }
13
+ export { Factory as factory, Factory };
@@ -1,3 +1,48 @@
1
- function factory() {
1
+ import { PrismaClient } from "@prisma/client";
2
+ import { ResultAsync } from "@stacksjs/errors";
3
+ const prisma = new PrismaClient();
4
+ class Factory {
5
+ constructor(factory) {
6
+ this.noOfItems = 5;
7
+ this.items = [];
8
+ this.columns = [];
9
+ this.factory = factory;
10
+ }
11
+ define(params) {
12
+ this.columns = params;
13
+ return this;
14
+ }
15
+ count(count = 5) {
16
+ this.noOfItems = count;
17
+ return this;
18
+ }
19
+ async make(count = 0) {
20
+ if (count)
21
+ this.noOfItems = count;
22
+ this.intiateColumns();
23
+ return ResultAsync.fromPromise(
24
+ await prisma[this.factory].createMany(
25
+ this.items,
26
+ true
27
+ ),
28
+ () => new Error("Failed to create the data")
29
+ );
30
+ }
31
+ async create(count = 0) {
32
+ if (count)
33
+ this.noOfItems = count;
34
+ this.intiateColumns();
35
+ return ResultAsync.fromPromise(
36
+ await prisma[this.factory].createMany(
37
+ this.items,
38
+ false
39
+ ),
40
+ () => new Error("Failed to create the data")
41
+ );
42
+ }
43
+ intiateColumns() {
44
+ for (let i = 0; i < this.noOfItems; i++)
45
+ this.items.push(this.columns);
46
+ }
2
47
  }
3
- export { factory };
48
+ export { Factory as factory, Factory };
@@ -1,2 +1,2 @@
1
- declare function seeder(): void;
1
+ declare function seeder(factoryName: any, count?: number): Promise<any>;
2
2
  export { seeder };
@@ -1,3 +1,5 @@
1
- function seeder() {
1
+ import { Factory } from "../factory/index.mjs";
2
+ function seeder(factoryName, count = 5) {
3
+ return new Factory(factoryName).make(count);
2
4
  }
3
5
  export { seeder };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@stacksjs/database",
3
3
  "type": "module",
4
- "version": "0.39.0",
5
- "packageManager": "pnpm@7.15.0",
4
+ "version": "0.40.0",
5
+ "packageManager": "pnpm@7.16.0",
6
6
  "description": "The Stacks database integration.",
7
7
  "author": "Chris Breuer",
8
8
  "license": "MIT",
@@ -39,10 +39,11 @@
39
39
  ],
40
40
  "engines": {
41
41
  "node": ">=v18.12.1",
42
- "pnpm": ">=7.15.0"
42
+ "pnpm": ">=7.16.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "vitest": "^0.25.1"
45
+ "@prisma/client": "^4.6.1",
46
+ "vitest": "^0.25.2"
46
47
  },
47
48
  "devDependencies": {
48
49
  "mkdist": "^0.4.0",