Skip to content

Commit b86ee17

Browse files
committed
TypeORM config in a another module. Select cases added
1 parent 367b835 commit b86ee17

File tree

2 files changed

+72
-26
lines changed

2 files changed

+72
-26
lines changed

netepscript.sh

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fi
2424

2525
echo -e "${YELLOW}\n2) We installed dependencies${NC}"
2626

27-
npm install express dotenv typeorm reflect-metadata pg
27+
npm install express dotenv
2828

2929
echo -e "${YELLOW}\n3) We installed development dependencies${NC}"
3030

@@ -38,10 +38,6 @@ npx tsc --init
3838
sed -i.bak '
3939
s/\/\/ *"rootDir": *".\/"/"rootDir": "\.\/src"/g
4040
s/\/\/ *"outDir": *".\/"/"outDir": "\.\/dist"/g
41-
s/\/\/ *"emitDecoratorMetadata": *true,/"emitDecoratorMetadata": true,/g
42-
s/\/\/ *"experimentalDecorators": *true,/"experimentalDecorators": true,/g
43-
s/\/\/ *"lib": *\[\],/"lib": ["ES6"],/g
44-
s/\/\/ *"strictPropertyInitialization": *true,/"strictPropertyInitialization": false,/g
4541
' tsconfig.json && rm tsconfig.json.bak
4642

4743
# Function to add lines to the end of the file before the last curly brace
@@ -151,36 +147,55 @@ module.exports = {
151147
};
152148
EOF
153149

154-
echo -e "${YELLOW}\n11) We configured data-source.ts ${NC}"
155-
156-
cat << EOF > src/config/data-source.ts
157-
import { DataSource } from 'typeorm';
158-
159-
export const AppDataSource = new DataSource({
160-
type: 'postgres',
161-
host: 'localhost',
162-
port: 5432,
163-
username: 'postgres',
164-
password: 'postgres',
165-
database: 'new_database', //This database must be created before initialize the typeorm
166-
dropSchema: false, //Erase database content when the server starts
167-
synchronize: true,
168-
logging: false, // Don't log queries in the console
169-
entities: [],
170-
subscribers: [],
171-
migrations: [],
172-
});
173-
EOF
174150

175151
# We set up the scripts in package.json
176-
echo -e "${YELLOW}\n12) We set up the scripts in package.json${NC}"
152+
echo -e "${YELLOW}\n11) We set up the scripts in package.json${NC}"
177153

178154
npx json -I -f package.json -e 'this.main="./dist/index.js"'
179155
npx json -I -f package.json -e 'this.scripts.start="nodemon"'
180156
npx json -I -f package.json -e 'this.scripts.build="tsc"'
181157
npx json -I -f package.json -e 'this.scripts.lint="eslint . --ext .ts"'
182158
npx json -I -f package.json -e 'this.scripts["lint:fix"]="eslint . --ext .ts --fix"'
183159

160+
echo -e "${YELLOW}\n12) Choose your database engine:${NC}"
161+
echo "1) PostgreSQL with Sequelize"
162+
echo "2) MySQL with Sequelize"
163+
echo "3) MongoDB with Mongoose"
164+
echo "4) typeORM with postgres"
165+
echo "5) No database engine"
166+
read -p "Enter your choice (1-5): " db_choice
167+
168+
case "$db_choice" in
169+
"1")
170+
echo "Installing PostgreSQL and Sequelize dependencies..."
171+
npm install pg sequelize
172+
npm install -D @types/pg @types/sequelize
173+
echo -e "\n# PostgreSQL Configuration\nDB_HOST=localhost\nDB_PORT=5432\nDB_NAME=your_database\nDB_USER=your_username\nDB_PASSWORD=your_password" >> .env
174+
;;
175+
"2")
176+
echo "Installing MySQL and Sequelize dependencies..."
177+
npm install mysql2 sequelize
178+
npm install -D @types/mysql @types/sequelize
179+
echo -e "\n# MySQL Configuration\nDB_HOST=localhost\nDB_PORT=3306\nDB_NAME=your_database\nDB_USER=your_username\nDB_PASSWORD=your_password" >> .env
180+
;;
181+
"3")
182+
echo "Installing MongoDB and Mongoose dependencies..."
183+
npm install mongodb mongoose
184+
npm install -D @types/mongodb @types/mongoose
185+
echo -e "\n# MongoDB Configuration\nMONGO_URI=mongodb://localhost:27017/your_database" >> .env
186+
;;
187+
"4")
188+
echo
189+
bash typeOrm.sh
190+
;;
191+
"5")
192+
echo "No database dependencies installed."
193+
;;
194+
*)
195+
echo "Invalid choice. No database dependencies installed."
196+
;;
197+
esac
198+
184199
PACKAGE_JSON="./package.json"
185200
sed -i 's/\^//g' "$PACKAGE_JSON"
186201

typeOrm.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
echo "Installing TypeORM dependencies..."
2+
npm install typeorm reflect-metadata pg
3+
4+
5+
#Typescript config file modification
6+
sed -i.bak '
7+
s/\/\/ *"emitDecoratorMetadata": *true,/"emitDecoratorMetadata": true,/g
8+
s/\/\/ *"experimentalDecorators": *true,/"experimentalDecorators": true,/g
9+
s/\/\/ *"lib": *\[\],/"lib": ["ES6"],/g
10+
s/\/\/ *"strictPropertyInitialization": *true,/"strictPropertyInitialization": false,/g
11+
' tsconfig.json && rm tsconfig.json.bak
12+
13+
14+
cat << EOF > src/config/data-source.ts
15+
import { DataSource } from 'typeorm';
16+
17+
export const AppDataSource = new DataSource({
18+
type: 'postgres',
19+
host: 'localhost',
20+
port: 5432,
21+
username: 'postgres',
22+
password: 'postgres',
23+
database: 'new_database', //This database must be created before initialize the typeorm
24+
dropSchema: false, //Erase database content when the server starts
25+
synchronize: true,
26+
logging: false, // Don't log queries in the console
27+
entities: [],
28+
subscribers: [],
29+
migrations: [],
30+
});
31+
EOF

0 commit comments

Comments
 (0)