首页 > 数据库 >node-oracledb typeorm 集成试用

node-oracledb typeorm 集成试用

时间:2023-10-14 22:12:56浏览次数:33  
标签:node const name oracledb dataSource typeorm

主要是测试下typeorm与node-oracledb thin 模式的集成

环境准备

  • docker-compose 文件
version: '3'
services:
   db:
      image: gvenzl/oracle-xe:21.3.0-slim
      ports:
         - "1521:1521"
      environment:
       - ORACLE_PASSWORD=Ccda5662E
       - APP_USER=dalong
       - APP_USER_PASSWORD=Ccda5662E

typeorm 集成

  • entity.js
const EntitySchema = require("typeorm").EntitySchema
module.exports = new EntitySchema({
    name: "sensor", // Will use table name `category` as default behaviour.
    tableName: "sensor", // Optional: Provide `tableName` property to override the default behaviour for table name.
    columns: {
        id: {
            primary: true,
            type: "varchar",
        },
        name: {
            type: "varchar",
        },
        address: {
            type: "varchar"
        }
    }
})
  • datasource.js
const typeorm = require("typeorm")
 
/**
 * data store operation for sensor data
 */
const dataSource = new typeorm.DataSource({
    type: "oracle",
    username: "dalong",
    password: "Ccda5662E",
    connectString:"127.0.0.1/XEPDB1",
    synchronize: true,
    entities: [require("./entity")],
})
 
module.exports = dataSource
  • index.js
const dataSource = require('./datasource')
async function run() {
    const dataSourceInstance = await dataSource.initialize()
    if(dataSourceInstance.isInitialized) {
        const sensorRepository = dataSourceInstance.getRepository('sensor')
        let body = {
            id: 11,
            name: 'test',
            address: 'test',
            status: true
        }
        let saveResult = await sensorRepository.save(body)
        console.log(saveResult)
        dataSourceInstance.destroy()
    }
}
run();

说明

node-oracledb typeorm 的集成还是比较方便的,没有什么问题

参考资料

https://github.com/oracle/node-oracledb
http://typeorm.io/#/

标签:node,const,name,oracledb,dataSource,typeorm
From: https://www.cnblogs.com/rongfengliang/p/17764819.html

相关文章

  • 在Node.js项目中使用node-postgres连接postgres以及报错指南
    什么是node-postgres官方文档nodepostgres是node.js模块的集合,用于与PostgreSQL数据库接口。它支持回调、promise、async/await、连接池、准备好的语句、游标、流式结果、C/C++绑定、富类型解析等等!就像PostgreSQL本身一样,它有很多功能:本文档旨在让您快速、正确地运行。它还试图......
  • 图文并茂手把手教你在MAC配置Android,nodejs环境,配置安卓真机支持投屏以及测试
    先说nodejs和npm这个很简单,只需要点击下面链接,安装node.js环境即可https://nodejs.org/zh-cn/AndroidAndroidStudio下载地址及版本说明Android开发者官网:https://developer.android.com/index.html(全球)https://developer.android.googl......
  • Argument for '--moduleResolution' option must be: 'node', Unknown compiler opt
    node_modules/@vue/tsconfig/tsconfig.json(12,25):errorTS6046:Argumentfor'--moduleResolution'optionmustbe:'node','classic','node16','nodenext'.node_modules/@vue/tsconfig/tsconfig.json(33,5):erro......
  • 本地有多个node切换不同版本node方法
    1.在当前使用的node版本,进行你要切换node版本的设置和配置npmconfigsetprefix"F:\node14\node_global"npmconfigsetcache"F:\node14\node_cache"假如你当前使用的是node14,这里就写node18,当前使用的是node18,这里就写node14。当然具体的路径名称根据你本地安装路径来配......
  • Node系列 — v8引擎堆内存详解
    参考:https://juejin.cn/post/6963170647207837710v8的堆内存限制Node程序中javascript的使用内存是有限制的,注意这个内存是指堆内存,在v8中,所有的js对象都存在堆中。在实际应用中不小心触碰到这个边界,进程就会退出。64位系统下为1.4GB,32位系统下为0.7GB。Node是基于v8......
  • [node]安装node后,可以在控制台进行简单的js文件测试
    1.在Windows操作系统安装好node之后,可以在任意文件地址,按下shift+鼠标右键,打开WindowsPowerShell。  或者在VSCode中,右键选择某文件夹,选择“在集成终端中打开”。2.输入node,可以查看安装好的node版本。3.按下ctrl+d,退出node。 在js文件所在目录打开终......
  • 开课吧前端1期.阶段3-1:软件的使用 (bower,atom, node)
    今天主要不讲课,试试环境软件:(推荐,有自己熟悉的用自己的)1.编辑器:atom支持插件: atom-typescript language-vue language-weex markdown-preview-plus2.服务器:wamp(apache+mysql)、xampp、nginx web服务器(要能支持php)——Apache 数据库——MySQL3.Phot......
  • ERROR in node_modules/rxjs/dist/types/internal/operators/combineLatest.d.ts(3,61
    原文链接:https://www.longkui.site/error/error-in-node_modules-rxjs/4839/angular项目,启动的时候报错。详细的报错如下:这个报错的原因比较简单,rxjs的版本不对,我用的是angular7可能和rxjs版本不匹配。解法方法也很简单,主要是降版本,我们找到项目的package.json把rxjs版本改成......
  • nodejs xxl-job-executor 客户端试用
    代码fork自awesomeoxc/xxl-job-executor-nodejs,进行了一些以来包的升级,同时发布npm包到npm仓库中,方便使用npm包名称npm包我已经发布npm仓库中了,可以直接使用@dalongrong/xxl-job-executor参考使用安装npminstall@dalongrong/xxl-job-executor--saveor......
  • MongoDB Node.js Driver and MongoClient All In One
    MongoDBNode.jsDriverandMongoClientAllInOneThenextgenerationNode.jsdriverforMongoDB$npmimongodb#OR$npmi-Smongodb#OR$npminstallmongodb--savehttps://mongodb.github.io/node-mongodb-native/index.htmlhttps://www.mongodb.com......