Skip to content

feat: mle-ts-ords-backend template #301 #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ The package offers the following templates, some of them connect to the database
- `node-react-todo`: A simple task manager template that uses Node.js and [React](https://react.dev/). It demonstrates the use of the database for Create, Read, Update and Delete (CRUD) operations. It is built by [vite](https://vitejs.dev/).
- `ords-remix-jwt-sample`: A full stack Concert Application made with [Remix](https://remix.run/) that showcases the [Oracle REST Data Services](https://www.oracle.com/database/technologies/appdev/rest.html) functionalities. Some extra configuration is required, learn more about it in the `ords-remix-jwt-sample` [Getting Started Guide](/templates/ords-remix-jwt-sample/README.md#getting-started).
- `mle-ts-sample`: A starter template application that demonstrates how backend applications can be developed using [Oracle Database Multilingual Engine (MLE)](https://docs.oracle.com/en/database/oracle/oracle-database/23/mlejs/introduction-to-mle.html). Requires SQLcl to be installed, for more information please read [README](/templates/mle-ts-sample/README.md)
- `mle-ts-ords-backend`: A starter template application that demonstrates how to expose MLE-based backend logic as RESTful endpoints using [Oracle REST Data Services](https://docs.oracle.com/en/database/oracle/oracle-rest-data-services/) (ORDS). This template requires both SQLcl and ORDS to be installed. For more information, please refer to the [README](/templates/mle-ts-ords-backend/).

Each of the templates include documentation for you to get started with them, as well as NPM scripts for you to use right after generating the application.

Expand Down
38 changes: 29 additions & 9 deletions generators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,34 @@ export default class extends Generator {
const { protocol, hostname, port, serviceName } = retrieveConnectionStringDetailsFromORAFile( path.join( walletPath, 'tnsnames.ora' ) );
this.options.connectionString = generateConnectionString( protocol, hostname, port, serviceName );
}
// Copy files that are common to all of the templates.
this.fs.copyTpl(
this.templatePath( this.options.templateChoice ),
this.destinationPath(),
{
appName: this.options.appName
}
);
if(this.options.templateChoice.includes('mle-ts-ords-backend')) {
const files = ['src/todos.ts', 'test/users.test.js', 'utils/db.mjs', 'utils/database/initdb.sql', 'utils/database/cleanup.sql', 'deploy.mjs', 'tsconfig.json',''];
files.forEach(file => {
this.fs.copyTpl(
this.templatePath(`../../templates/mle-ts-sample/${file}`),
this.destinationPath(file),
{
appName: this.options.appName
}
);
});
// Copy files that are common to all of the templates.
this.fs.copyTpl(
this.templatePath( this.options.templateChoice ),
this.destinationPath(),
this.options
);
} else {
// Copy files that are common to all of the templates.
this.fs.copyTpl(
this.templatePath( this.options.templateChoice ),
this.destinationPath(),
{
appName: this.options.appName
}
);
}

this.fs.copy(
this.templatePath(`${ path.dirname( this.options.templateChoice ) }/app/.github`),
this.destinationPath('.github')
Expand Down Expand Up @@ -142,7 +162,7 @@ export default class extends Generator {
this.templatePath( `${this.options.templateChoice}/.env.example` ),
this.destinationPath( '.env.example' ),
);
} else if (this.options.templateChoice.includes('mle-ts-sample')) {
} else if (this.options.templateChoice.includes('mle-ts-sample') || this.options.templateChoice.includes('mle-ts-ords-backend')) {
if( 'walletPath' in this.options ) {
this.fs.copyTpl(
this.templatePath( `${this.options.templateChoice}/.env.example.wallet` ),
Expand Down
62 changes: 46 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export default class Generate extends Command {
'template': Flags.string({
char: 't',
description: 'Template to use',
options: ['node-vanilla', 'node-react', 'node-vue', 'node-react-todo', 'node-jet', 'node-angular', 'ords-remix-jwt-sample', 'mle-ts-sample'],
options: ['node-vanilla', 'node-react', 'node-vue', 'node-react-todo', 'node-jet', 'node-angular', 'ords-remix-jwt-sample', 'mle-ts-sample', 'mle-ts-ords-backend'],
multiple: false
}),

Expand Down Expand Up @@ -314,6 +314,7 @@ export default class Generate extends Command {
const databaseServiceName = flags['db-service-name'] ?? '';
const databaseUsername = flags['db-username'] ?? '';
const sqlclPath = flags['sqlcl'] ?? '';
const ordsHost = flags['ords-host'] ?? '';

// TODO: Validate and use wallet path
const walletPathDirectory = flags['wallet-path'] ? flags['wallet-path'] : '';
Expand Down Expand Up @@ -379,6 +380,11 @@ export default class Generate extends Command {
value: 'mle-ts-sample',
description: 'This creates an empty project with MLE and Oracle database connection starter code.'
},
{
name: 'mle-ts-ords-backend',
value: 'mle-ts-ords-backend',
description: 'Creates a starter project with MLE integration, Oracle Database connectivity, and scaffolded ORDS REST endpoints.'
},
],
pageSize: 10,
default: 'node-vanilla'
Expand Down Expand Up @@ -476,8 +482,10 @@ export default class Generate extends Command {

// This will be config object for the basic connection type.
Object.assign(configObject, {
connectionString: generateConnectionString( protocol, hostname, port, serviceValue )
});
connectionString: generateConnectionString( protocol, hostname, port, serviceValue ),
serviceValue: serviceValue,
databasePort: port
});
} else if( databaseConnectionType === 'walletPath' ) {
let walletPath = '';

Expand Down Expand Up @@ -509,23 +517,29 @@ export default class Generate extends Command {
// This is the config object that represents the wallet connection type.
Object.assign(configObject, {
walletPath: walletPath,
walletPassword: walletPassword
walletPassword: walletPassword,
serviceValue: "",
databasePort: 8080,
});
}

if(templateChoice !== 'ords-remix-jwt-sample'){
if(templateChoice !== 'ords-remix-jwt-sample') {
// Ask the user for the database connection username.
let databaseUser = databaseUsername === '' ? await input(
{
message: 'What\'s your database username?',
validate ( input ) {
return input.trim().length === 0 ? 'This field cannot be empty!' : true;
}
},
) : databaseUsername;
if (templateChoice === 'mle-ts-ords-backend') {
databaseUser = databaseUser.toLowerCase();
}
Object.assign( configObject, {
connectionUsername: databaseUsername === '' ? await input(
{
message: 'What\'s your database username?',
validate ( input ) {
return input.trim().length === 0 ? 'This field cannot be empty!' : true;
}
},
) : databaseUsername
} );

connectionUsername: databaseUser
});

// Ask the user for the database connection password.
Object.assign( configObject, {
connectionPassword: await password(
Expand All @@ -540,7 +554,8 @@ export default class Generate extends Command {
} );
}

if(templateChoice == 'mle-ts-sample'){
if(templateChoice == 'mle-ts-sample' || templateChoice == 'mle-ts-ords-backend')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use strict comparison === instead

{
// Ask the user for the path to SQLcl
Object.assign( configObject, {
sqlclPath: sqlclPath === '' ? await input(
Expand All @@ -552,6 +567,21 @@ export default class Generate extends Command {
},
) : sqlclPath
});
if (templateChoice == 'mle-ts-ords-backend')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use strict comparison === instead

{
// Ask the user for the path to SQLcl
Object.assign( configObject, {
ordsHost: ordsHost === '' ? await input(
{
message: 'Please provide ORDS Base URL: ',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the ORDS base path provided contains a slash at the end, the BASE_URL for tests generates something like <my_hostname>/ords//<my_db_user> with a double slash which makes tests fail (test/rest.test.js)

validate ( input ) {
return input.trim().length === 0 ? 'This field cannot be empty!' : true;
},
default: 'http://localhost:8080/ords'
},
) : ordsHost
});
}
}

generateDatabaseApp( configObject );
Expand Down
16 changes: 16 additions & 0 deletions templates/mle-ts-ords-backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Database User
DB_USER=<%= connectionUsername %>
# Database User Password
DB_PASSWORD=<%= connectionPassword %>
# Connection string to your Autonomous Database/
# Oracle Database instance
CONNECT_STRING=<%= connectionString %>
# Oracle MLE Module name
MLE_MODULE=
# Optional HTTP Proxy Settings
# HTTPS_PROXY=
# HTTPS_PROXY_PORT=

# Path to your local SQL Developer Command Line
# installation
SQL_CL_PATH=<%= sqlclPath %>
19 changes: 19 additions & 0 deletions templates/mle-ts-ords-backend/.env.example.wallet
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Path to database wallet
WALLET_PATH=<%= walletPath %>
WALLET_PASSWORD=<%= walletPassword %>
# Database User
DB_USER=<%= connectionUsername %>
# Database User Password
DB_PASSWORD=<%= connectionPassword %>
# Connection string to your Autonomous Database/
# Oracle Database instance
CONNECT_STRING=<%= connectionString %>
# Oracle MLE Module name
MLE_MODULE=
# Optional HTTP Proxy Settings
# HTTPS_PROXY=
# HTTPS_PROXY_PORT=

# Path to your local SQL Developer Command Line
# installation
SQL_CL_PATH=<%= sqlclPath %>
22 changes: 22 additions & 0 deletions templates/mle-ts-ords-backend/.gitignore.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.DS_Store

/.env
/.env.*
!/.env.example
!/.env.*.example
/server/utils/db/wallet
Loading