具有React Native的Typeorm

Ami*_*mit 5 sqlite react-native typeorm

我使用创建了一个新的虚拟应用程序react-native init test,然后按照说明添加typeorm。在我的App.js中,包括import {getManager} from 'typeorm',然后运行react-native run-ios

我在Metro-Bundler中看到以下错误:

Error: Unable to resolve module path from /Users/amit/Code/test/node_modules/typeorm/platform/PlatformTools.js: Module path does not exist in the Haste module map
Run Code Online (Sandbox Code Playgroud)

这是显示问题的示例存储库:在此处输入链接描述

不知道我是否错过了设置!任何帮助都非常欢迎!

小智 5

不幸的是,从“typeorm”模块导入不起作用,因为反应本机项目不完全使用节点平台。从“typeorm/浏览器”导入将起作用。这是一个示例项目:https://github.com/typeorm/react-native-example

确保您创建的连接对象不使用任何对项目文件系统的引用。避免使用类似的东西:

import { CountSession } from '../biopro-mobile-database/entities/count_session';

   const connection = await createConnection({
            name: 'liteDb_3',
            type: 'react-native',
            database: 'biopro_mobile.sqlite',
            location: 'default',
            synchronize: false,
            logging: true,
            entities: ["../biopro-mobile-database/entities/**/*.ts"],
          })
Run Code Online (Sandbox Code Playgroud)

避免实体: ["../biopro-mobile-database/entities/ /*.ts"],** 而是使用类似以下内容:

import { EquipmentCounted } from '../biopro-mobile-database/entities/equipment_counted';
import { CountSession } from '../biopro-mobile-database/entities/count_session';

   const connection = await createConnection({
            name: 'liteDb_3',
            type: 'react-native',
            database: 'biopro_mobile.sqlite',
            location: 'default',
            synchronize: false,
            logging: true,
            entities: [
              CountSession,
              EquipmentCounted,
            ],
          })
Run Code Online (Sandbox Code Playgroud)

  • 有人在生产中的 React Native 应用程序中使用 TypeORM 吗?我很想找到 Realm 的 ORM 替代品。我无法让 https://github.com/typeorm/react-native-example 在 Android 或 iOS 上运行。https://github.com/typeorm/react-native-example/issues/4 https://github.com/typeorm/react-native-example/issues/2 (3认同)