Skip to content

Commit

Permalink
feat : add Orm
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamensuli committed Mar 9, 2024
1 parent ce29e61 commit cda9879
Show file tree
Hide file tree
Showing 47 changed files with 2,649 additions and 133 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dist/
node_modules/
tmp/
nodefony/config/certificates
nodefony/databases/*

# Ignore les fichiers générés par TypeScript
*.tsbuildinfo
Expand Down
5 changes: 3 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import config from "./nodefony/config/config";
* The App class extends the Module class and represents an application entry point.
*/
@modules([
"@nodefony/sequelize",
"@nodefony/mongoose",
"@nodefony/http",
"@nodefony/security",
"@nodefony/framework",
"@nodefony/sequelize",
"@nodefony/security",
"@nodefony/test",
])
@controllers([AppController])
Expand Down
11 changes: 9 additions & 2 deletions nodefony/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import path from "node:path";
import { Nodefony } from "nodefony";
const kernel = Nodefony.kernel;
import http from "./module-http-config";
import http from "./modules/http-config";
import sequelize from "./modules/sequelize-config";
import mongoose from "./modules/mongoose-config";
import pm2 from "./pm2/pm2.config";

let CDN = null;
Expand All @@ -44,8 +46,9 @@ switch (kernel?.environment) {
unitTest = true;
domainCheck = true;
}
//console.log(sequelize.connectors.nodefony.options);

export default {
const config = {
watch: true,
domain: "127.0.0.1", // "0.0.0.0" "selectAuto"
//domain: "selectAuto",
Expand Down Expand Up @@ -161,4 +164,8 @@ export default {
* OVERRIDE modules config
*/
"module-http": http,
"module-sequelize": sequelize,
"module-mongoose": mongoose,
};

export default config;
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ switch (kernel?.environment) {
export default {
rejectUnauthorized,
certificates,
session: {
handler: "sequelize",
},
};
43 changes: 43 additions & 0 deletions nodefony/config/modules/mongoose-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import nodefony from "nodefony";

/**
* OVERRIDE ORM BUNDLE MONGOOSE
*
* @see MONGO BUNDLE config for more options
* @more options https://mongoosejs.com/docs/connections.html
* https://mongoosejs.com/docs/api.html#mongoose_Mongoose-createConnection
*
* By default nodefony create connector name nodefony
* for manage Sessions / Users
*/

const connectors = {
nodefony: {},
};

switch (nodefony.kernel?.appEnvironment.environment) {
case "production":
case "development":
default:
connectors.nodefony = {
host: "localhost",
port: 27017,
dbname: "nodefony",
// credentials: vault,
options: {
user: "nodefony",
pass: "nodefony",
maxPoolSize: 50,
serverSelectionTimeoutMS: 5000,
socketTimeoutMS: 5000,
connectTimeoutMS: 5000,
},
};
}

const config = {
debug: true,
connectors,
};

export default config;
88 changes: 88 additions & 0 deletions nodefony/config/modules/sequelize-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import path from "path";
import nodefony, { Kernel } from "nodefony";
import { sequelize } from "@nodefony/sequelize";

const config = {
connectors: {
nodefony: {
driver: "sqlite",
dbname: path.resolve(
(nodefony.kernel as Kernel).path,
"nodefony",
"databases",
"nodefony.db"
),
options: {
dialect: "sqlite",
// isolationLevel: Transaction.ISOLATION_LEVELS.SERIALIZABLE,
retry: {
match: [/Deadlock/i, "SQLITE_BUSY"],
max: 5,
},
pool: {
max: 5,
min: 0,
idle: 10000,
},
},
},
// nodefony: {
// driver: "mysql",
// dbname: "nodefony",
// username: "root",
// password: "nodefony",
// //credentials: vault,
// options: {
// dialect: "mysql",
// host: "localhost",
// port: "3306",
// //isolationLevel: Transaction.ISOLATION_LEVELS.SERIALIZABLE,
// retry: {
// match: [
// sequelize.ConnectionError,
// sequelize.ConnectionTimedOutError,
// sequelize.TimeoutError,
// /Deadlock/i,
// ],
// max: 5,
// },
// pool: {
// max: 20,
// min: 0,
// idle: 10000,
// acquire: 60000,
// },
// },
// },
// nodefony: {
// driver: "postgres",
// dbname: "nodefony",
// username: "postgres",
// password: "nodefony",
// //credentials: vault,
// options: {
// dialect: "postgres",
// host: "localhost",
// port: "5432",
// //isolationLevel: Transaction.ISOLATION_LEVELS.SERIALIZABLE,
// retry: {
// match: [
// sequelize.ConnectionError,
// sequelize.ConnectionTimedOutError,
// sequelize.TimeoutError,
// /Deadlock/i,
// ],
// max: 5,
// },
// pool: {
// max: 20,
// min: 0,
// idle: 10000,
// acquire: 60000,
// },
// },
// },
},
};

export default config;
Loading

0 comments on commit cda9879

Please sign in to comment.