From a785d3d08434115cf519afc7d459c1ff573d9f2b Mon Sep 17 00:00:00 2001 From: jiu33 <294125069@qq.com> Date: Fri, 31 May 2024 08:43:19 +0800 Subject: [PATCH 01/11] Create index.js --- javascript/index.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 javascript/index.js diff --git a/javascript/index.js b/javascript/index.js new file mode 100644 index 0000000..7c88da1 --- /dev/null +++ b/javascript/index.js @@ -0,0 +1,28 @@ +onst mysql = require('mysql2'); + +const connection = mysql.createConnection({ + host: '127.0.0.1', // OceanBase服务器地址 + port: 2881, // OceanBase端口 + user: 'root', // 数据库用户名 + password: '', // 数据库密码 + database: 'test' // 数据库名称 +}); + +// 连接到数据库 +connection.connect(error => { + if (error) { + return console.error('连接到OceanBase数据库失败: ' + error.message); + } + + console.log('成功连接到OceanBase数据库'); + + // 这里可以执行其他数据库操作 + + // 关闭连接 + connection.end(err => { + if (err) { + return console.error('关闭数据库连接失败: ' + err.message); + } + console.log('关闭数据库连接成功'); + }); +}); From 5f86813bd46b24947ffe1ace4e4c329921e1d9c0 Mon Sep 17 00:00:00 2001 From: jiu33 <294125069@qq.com> Date: Fri, 31 May 2024 08:44:53 +0800 Subject: [PATCH 02/11] Delete javascript/index.js --- javascript/index.js | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 javascript/index.js diff --git a/javascript/index.js b/javascript/index.js deleted file mode 100644 index 7c88da1..0000000 --- a/javascript/index.js +++ /dev/null @@ -1,28 +0,0 @@ -onst mysql = require('mysql2'); - -const connection = mysql.createConnection({ - host: '127.0.0.1', // OceanBase服务器地址 - port: 2881, // OceanBase端口 - user: 'root', // 数据库用户名 - password: '', // 数据库密码 - database: 'test' // 数据库名称 -}); - -// 连接到数据库 -connection.connect(error => { - if (error) { - return console.error('连接到OceanBase数据库失败: ' + error.message); - } - - console.log('成功连接到OceanBase数据库'); - - // 这里可以执行其他数据库操作 - - // 关闭连接 - connection.end(err => { - if (err) { - return console.error('关闭数据库连接失败: ' + err.message); - } - console.log('关闭数据库连接成功'); - }); -}); From 796225917fcdffc4a4d5bde3cc7bc391e65b99c7 Mon Sep 17 00:00:00 2001 From: jiu33 <294125069@qq.com> Date: Fri, 31 May 2024 08:45:31 +0800 Subject: [PATCH 03/11] Create README-CN.md --- javascript/mysql2/README-CN.md | 59 ++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 javascript/mysql2/README-CN.md diff --git a/javascript/mysql2/README-CN.md b/javascript/mysql2/README-CN.md new file mode 100644 index 0000000..5290d72 --- /dev/null +++ b/javascript/mysql2/README-CN.md @@ -0,0 +1,59 @@ +# javascript连接OceanBase 指南 + +[English](README.md) | 简体中文 + +本文介绍如何通过javascript连接 OceanBase 数据库。 + +## 准备工作 + +需要创建一个项目,确认nodejs,npm,mysql2已经安装安装。 + +命令 + +``` +mkdir example +cd example +npm init -y + +npm install mysql2 + +``` + +创建 [example.js](example.js) 文件 + +``` +onst mysql = require('mysql2'); + +const connection = mysql.createConnection({ + host: '127.0.0.1', // OceanBase服务器地址 + port: 2881, // OceanBase端口 + user: 'root', // 数据库用户名 + password: '', // 数据库密码 + database: 'test' // 数据库名称 +}); + +// 连接到数据库 +connection.connect(error => { + if (error) { + return console.error('连接到OceanBase数据库失败: ' + error.message); + } + + console.log('成功连接到OceanBase数据库'); + + // 这里可以执行其他数据库操作 + + // 关闭连接 + connection.end(err => { + if (err) { + return console.error('关闭数据库连接失败: ' + err.message); + } + console.log('关闭数据库连接成功'); + }); +}); +``` + +修改代码中的连接信息,之后你就可以直接使用命令行运行示例代码。 + +```bash +sh run.sh +``` From a25ac63898e505d81560026e12f80aadb3a03186 Mon Sep 17 00:00:00 2001 From: jiu33 <294125069@qq.com> Date: Fri, 31 May 2024 08:45:51 +0800 Subject: [PATCH 04/11] Create index.js --- javascript/mysql2/index.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 javascript/mysql2/index.js diff --git a/javascript/mysql2/index.js b/javascript/mysql2/index.js new file mode 100644 index 0000000..7c88da1 --- /dev/null +++ b/javascript/mysql2/index.js @@ -0,0 +1,28 @@ +onst mysql = require('mysql2'); + +const connection = mysql.createConnection({ + host: '127.0.0.1', // OceanBase服务器地址 + port: 2881, // OceanBase端口 + user: 'root', // 数据库用户名 + password: '', // 数据库密码 + database: 'test' // 数据库名称 +}); + +// 连接到数据库 +connection.connect(error => { + if (error) { + return console.error('连接到OceanBase数据库失败: ' + error.message); + } + + console.log('成功连接到OceanBase数据库'); + + // 这里可以执行其他数据库操作 + + // 关闭连接 + connection.end(err => { + if (err) { + return console.error('关闭数据库连接失败: ' + err.message); + } + console.log('关闭数据库连接成功'); + }); +}); From 82863a6427bc49c05a215bc09891013bb0b2540d Mon Sep 17 00:00:00 2001 From: jiu33 <294125069@qq.com> Date: Fri, 31 May 2024 08:46:15 +0800 Subject: [PATCH 05/11] Create README.md --- javascript/mysql2/README.md | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 javascript/mysql2/README.md diff --git a/javascript/mysql2/README.md b/javascript/mysql2/README.md new file mode 100644 index 0000000..88b6bb9 --- /dev/null +++ b/javascript/mysql2/README.md @@ -0,0 +1,59 @@ +# JavaScript Connection OceanBase Guide + +English | [简体中文](README-CN.md) + +This article introduces how to connect to the OceanBase database through JavaScript. + +## prepare + +We need to create a project to confirm nodejs, NPM, mysql2 has been installed and installed. + +command + +``` +mkdir example +cd example +npm init -y + +npm install mysql2 + +``` + +创建 [example.js](example.js) 文件 + +``` +onst mysql = require('mysql2'); + +const connection = mysql.createConnection({ + host: '127.0.0.1', // OceanBase服务器地址 + port: 2881, // OceanBase端口 + user: 'root', // 数据库用户名 + password: '', // 数据库密码 + database: 'test' // 数据库名称 +}); + +// 连接到数据库 +connection.connect(error => { + if (error) { + return console.error('连接到OceanBase数据库失败: ' + error.message); + } + + console.log('成功连接到OceanBase数据库'); + + // 这里可以执行其他数据库操作 + + // 关闭连接 + connection.end(err => { + if (err) { + return console.error('关闭数据库连接失败: ' + err.message); + } + console.log('关闭数据库连接成功'); + }); +}); +``` + +Modify the connection information in the code, and then you can directly run the example code using the command line. + +```bash +sh run.sh +``` From 6671793a8ad086080dacc945344a96c59ec7dc20 Mon Sep 17 00:00:00 2001 From: jiu33 <294125069@qq.com> Date: Fri, 31 May 2024 08:46:42 +0800 Subject: [PATCH 06/11] Create run.sh --- javascript/mysql2/run.sh | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 javascript/mysql2/run.sh diff --git a/javascript/mysql2/run.sh b/javascript/mysql2/run.sh new file mode 100644 index 0000000..bd16d03 --- /dev/null +++ b/javascript/mysql2/run.sh @@ -0,0 +1,8 @@ +mkdir example +cd example +npm init -y + +npm install mysql2 + +cp ../index.js ./ +node index.js From 038835cb3637f373868b46df3faf4f92ffba037c Mon Sep 17 00:00:00 2001 From: jiu33 <294125069@qq.com> Date: Fri, 31 May 2024 08:48:13 +0800 Subject: [PATCH 07/11] Create javascript.yml --- .github/workflows/javascript.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/javascript.yml diff --git a/.github/workflows/javascript.yml b/.github/workflows/javascript.yml new file mode 100644 index 0000000..1fd7ab5 --- /dev/null +++ b/.github/workflows/javascript.yml @@ -0,0 +1,24 @@ +name: JavaScript CI + +on: + push: + paths: + - '.github/workflows/javascript.yml' + - 'javascript/**' + pull_request: + paths: + - '.github/workflows/javascript.yml' + - 'javascript/**' + +jobs: + ci: + strategy: + matrix: + module: + - name: 'mysql2' + with_oceanbase_container: true + uses: ./.github/workflows/basic-workflow.yml + with: + language: 'javascript' + module: ${{ matrix.module.name }} + with_oceanbase_container: ${{ matrix.module.with_oceanbase_container }} From 688c515adce49784c4dc8d554927ee7121bf1acb Mon Sep 17 00:00:00 2001 From: jiu33 <294125069@qq.com> Date: Fri, 31 May 2024 09:12:23 +0800 Subject: [PATCH 08/11] Update index.js --- javascript/mysql2/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/mysql2/index.js b/javascript/mysql2/index.js index 7c88da1..252354b 100644 --- a/javascript/mysql2/index.js +++ b/javascript/mysql2/index.js @@ -1,4 +1,4 @@ -onst mysql = require('mysql2'); +const mysql = require('mysql2'); const connection = mysql.createConnection({ host: '127.0.0.1', // OceanBase服务器地址 From 00273ca777ce83f94eb8be7872b70c48701bbed8 Mon Sep 17 00:00:00 2001 From: jiu33 <294125069@qq.com> Date: Fri, 31 May 2024 09:19:36 +0800 Subject: [PATCH 09/11] Update README.md --- javascript/mysql2/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/javascript/mysql2/README.md b/javascript/mysql2/README.md index 88b6bb9..55dd3ce 100644 --- a/javascript/mysql2/README.md +++ b/javascript/mysql2/README.md @@ -19,10 +19,10 @@ npm install mysql2 ``` -创建 [example.js](example.js) 文件 +创建 [index.js](index.js) 文件 ``` -onst mysql = require('mysql2'); +const mysql = require('mysql2'); const connection = mysql.createConnection({ host: '127.0.0.1', // OceanBase服务器地址 From 21579ab84b1a8cfd3947911057ea23042aa7d4c6 Mon Sep 17 00:00:00 2001 From: jiu33 <294125069@qq.com> Date: Fri, 31 May 2024 09:20:15 +0800 Subject: [PATCH 10/11] Update README-CN.md --- javascript/mysql2/README-CN.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/javascript/mysql2/README-CN.md b/javascript/mysql2/README-CN.md index 5290d72..12933a4 100644 --- a/javascript/mysql2/README-CN.md +++ b/javascript/mysql2/README-CN.md @@ -19,10 +19,10 @@ npm install mysql2 ``` -创建 [example.js](example.js) 文件 +创建 [index.js](index.js) 文件 ``` -onst mysql = require('mysql2'); +const mysql = require('mysql2'); const connection = mysql.createConnection({ host: '127.0.0.1', // OceanBase服务器地址 From be898092680ca0f5e50454a91760d0104766d445 Mon Sep 17 00:00:00 2001 From: jiu33 <294125069@qq.com> Date: Fri, 31 May 2024 09:40:33 +0800 Subject: [PATCH 11/11] Update README.md --- javascript/mysql2/README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/javascript/mysql2/README.md b/javascript/mysql2/README.md index 55dd3ce..52d0d0c 100644 --- a/javascript/mysql2/README.md +++ b/javascript/mysql2/README.md @@ -19,35 +19,35 @@ npm install mysql2 ``` -创建 [index.js](index.js) 文件 +create [index.js](index.js) file ``` const mysql = require('mysql2'); const connection = mysql.createConnection({ - host: '127.0.0.1', // OceanBase服务器地址 - port: 2881, // OceanBase端口 - user: 'root', // 数据库用户名 - password: '', // 数据库密码 - database: 'test' // 数据库名称 + host: '127.0.0.1', // OceanBase address + port: 2881, // OceanBase port + user: 'root', // username + password: '', // passwd + database: 'test' // database }); -// 连接到数据库 +// Connection OceanBase server connection.connect(error => { if (error) { - return console.error('连接到OceanBase数据库失败: ' + error.message); + return console.error('Connection OceanBase faild: ' + error.message); } - console.log('成功连接到OceanBase数据库'); + console.log('Connection OceanBase Successd'); - // 这里可以执行其他数据库操作 + // Other Database Operations - // 关闭连接 + // Close Connection connection.end(err => { if (err) { - return console.error('关闭数据库连接失败: ' + err.message); + return console.error('Close Connection Faild: ' + err.message); } - console.log('关闭数据库连接成功'); + console.log('Close Connection Successd'); }); }); ```