UNPKG

gen-jhipster

Version:

Spring Boot + Angular/React/Vue in one handy generator

148 lines (147 loc) 5.35 kB
/** * Copyright 2013-2024 the original author or authors from the JHipster project. * * This file is part of the JHipster project, see https://www.jhipster.tech/ * for more information. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { databaseTypes } from '../../../lib/jhipster/index.js'; const { H2_DISK, H2_MEMORY, MARIADB, MSSQL, MYSQL, ORACLE, POSTGRESQL } = databaseTypes; const H2_PROD_DATABASE_MODE = { [MYSQL]: ';MODE=MYSQL', [MARIADB]: ';MODE=LEGACY', }; const h2GetProdDatabaseData = (databaseType, { extraOptions = '' }, { prodDatabaseType, buildDirectory, itests, localDirectory, protocolSuffix }) => { const data = {}; if (protocolSuffix) { data.protocolSuffix = protocolSuffix; } if (H2_DISK === databaseType) { if (!localDirectory && !buildDirectory) { throw new Error(`'localDirectory' option should be provided for ${databaseType} databaseType`); } if (localDirectory) { localDirectory = `${localDirectory}/`; } else { localDirectory = `${buildDirectory}h2db/${itests ? 'testdb/' : 'db/'}`; } } if (itests && H2_MEMORY === databaseType) { data.port = ':12344'; } const h2ProdDatabaseMode = prodDatabaseType ? (H2_PROD_DATABASE_MODE[prodDatabaseType] ?? '') : ''; return { ...data, localDirectory, extraOptions: `${extraOptions}${h2ProdDatabaseMode}`, }; }; const databaseData = { [MSSQL]: { name: 'SQL Server', protocolSuffix: 'sqlserver://', jdbcDriver: '', hibernateDialect: 'org.hibernate.dialect.SQLServer2012Dialect', port: ':1433;database=', defaultUsername: 'SA', defaultPassword: 'yourStrong(!)Password', jdbc: { extraOptions: ';encrypt=false', }, r2dbc: { protocolSuffix: 'mssql://', port: ':1433/', }, }, [MARIADB]: { name: 'MariaDB', protocolSuffix: 'mariadb://', jdbcDriver: 'org.mariadb.jdbc.Driver', hibernateDialect: 'org.hibernate.dialect.MariaDB103Dialect', port: ':3306/', extraOptions: '?useLegacyDatetimeCode=false', defaultUsername: 'root', constraintNameMaxLength: 64, tableNameMaxLength: 64, r2dbc: { // TODO switch to mariadb if r2dbc-mariadb is reinstated protocolSuffix: 'mysql://', }, }, [MYSQL]: { name: 'MySQL', protocolSuffix: 'mysql://', jdbcDriver: 'com.mysql.cj.jdbc.Driver', hibernateDialect: 'org.hibernate.dialect.MySQL8Dialect', tableNameMaxLength: 64, constraintNameMaxLength: 64, port: ':3306/', extraOptions: '?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&createDatabaseIfNotExist=true', defaultUsername: 'root', }, [ORACLE]: { name: 'Oracle', protocolSuffix: 'oracle:thin:@', jdbcDriver: 'oracle.jdbc.OracleDriver', hibernateDialect: 'org.hibernate.dialect.Oracle12cDialect', port: ':1521:', defaultUsername: 'system', defaultPassword: 'oracle', defaultDatabaseName: 'xe', constraintNameMaxLength: 128, tableNameMaxLength: 128, }, [POSTGRESQL]: { name: 'PostgreSQL', protocolSuffix: 'postgresql://', jdbcDriver: 'org.postgresql.Driver', hibernateDialect: 'org.hibernate.dialect.PostgreSQLDialect', port: ':5432/', constraintNameMaxLength: 63, tableNameMaxLength: 63, }, [H2_DISK]: { name: 'H2Disk', protocolSuffix: 'h2:file:', jdbcDriver: 'org.h2.Driver', hibernateDialect: 'org.hibernate.dialect.H2Dialect', getData: options => h2GetProdDatabaseData(H2_DISK, { extraOptions: ';DB_CLOSE_DELAY=-1' }, options), r2dbc: { protocolSuffix: 'h2:file:///', }, }, [H2_MEMORY]: { name: 'H2Memory', protocolSuffix: 'h2:mem:', jdbcDriver: 'org.h2.Driver', hibernateDialect: 'org.hibernate.dialect.H2Dialect', getData: options => h2GetProdDatabaseData(H2_MEMORY, { extraOptions: ';DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE' }, options), r2dbc: { protocolSuffix: 'h2:mem:///', }, }, }; export default databaseData; export function getDatabaseData(databaseType) { if (databaseData[databaseType] === undefined) { throw new Error(`Database data not found for database ${databaseType}`); } return databaseData[databaseType]; } export const getDBCExtraOption = databaseType => { const databaseDataForType = databaseData[databaseType]; const { extraOptions = '' } = databaseDataForType; return extraOptions; };