lapeh 2.1.1 → 2.1.2
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 +2 -1
- package/scripts/make-model.js +7 -7
- package/src/prisma.ts +18 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lapeh",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "Framework API Express yang siap pakai (Standardized)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"license": "MIT",
|
|
46
46
|
"type": "commonjs",
|
|
47
47
|
"dependencies": {
|
|
48
|
+
"@prisma/adapter-mariadb": "7.2.0",
|
|
48
49
|
"@prisma/adapter-pg": "7.2.0",
|
|
49
50
|
"@prisma/client": "7.2.0",
|
|
50
51
|
"bcryptjs": "3.0.3",
|
package/scripts/make-model.js
CHANGED
|
@@ -26,13 +26,13 @@ if (!fs.existsSync(modelsDir)) {
|
|
|
26
26
|
fs.mkdirSync(modelsDir, { recursive: true });
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const content = `model ${tableName} {
|
|
30
|
-
id BigInt @id @default(autoincrement())
|
|
31
|
-
name String
|
|
32
|
-
createdAt DateTime? @default(now())
|
|
33
|
-
updatedAt DateTime? @updatedAt
|
|
34
|
-
}
|
|
35
|
-
`;
|
|
29
|
+
const content = `model ${tableName} {
|
|
30
|
+
id BigInt @id @default(autoincrement())
|
|
31
|
+
name String
|
|
32
|
+
createdAt DateTime? @default(now())
|
|
33
|
+
updatedAt DateTime? @updatedAt
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
36
|
|
|
37
37
|
fs.writeFileSync(modelPath, content);
|
|
38
38
|
|
package/src/prisma.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PrismaClient } from "../generated/prisma";
|
|
2
2
|
import { PrismaPg } from "@prisma/adapter-pg";
|
|
3
|
+
import { PrismaMariaDb } from "@prisma/adapter-mariadb";
|
|
3
4
|
|
|
4
5
|
const url = process.env.DATABASE_URL || "";
|
|
5
6
|
const provider = (process.env.DATABASE_PROVIDER || "").toLowerCase();
|
|
@@ -10,7 +11,23 @@ if (provider === "postgresql" || url.startsWith("postgres")) {
|
|
|
10
11
|
const adapter = new PrismaPg({ connectionString: url });
|
|
11
12
|
prisma = new PrismaClient({ adapter });
|
|
12
13
|
} else {
|
|
13
|
-
|
|
14
|
+
if (provider === "mysql" || url.startsWith("mysql")) {
|
|
15
|
+
try {
|
|
16
|
+
const u = new URL(url);
|
|
17
|
+
const adapter = new PrismaMariaDb({
|
|
18
|
+
host: u.hostname,
|
|
19
|
+
port: Number(u.port || "3306"),
|
|
20
|
+
user: decodeURIComponent(u.username),
|
|
21
|
+
password: decodeURIComponent(u.password),
|
|
22
|
+
database: u.pathname.replace("/", ""),
|
|
23
|
+
} as any);
|
|
24
|
+
prisma = new PrismaClient({ adapter });
|
|
25
|
+
} catch {
|
|
26
|
+
prisma = new PrismaClient({});
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
prisma = new PrismaClient({});
|
|
30
|
+
}
|
|
14
31
|
}
|
|
15
32
|
|
|
16
33
|
export { prisma };
|