世博会类型ORM EntityMetadataNotFoundError
Expo TypeORM EntityMetadataNotFoundError
我正在尝试通过驱动程序 expo-sqlite 在 expo 项目上使用 typeorm,但我一直卡在这个元数据 EntityMetadataNotFoundError: No metadata for "User" was found.
错误上。据我所知,config.ts
上的这一行 entities: [User]
与错误有关,搜索它我发现了一些 people discussing bad configuration on entities, but they are pointing directly to the filesystem path, and I'm passing through the DataSource the User class. I wrote this code based on This repo and TypeORM strange? example
我已经试过了:
entities: ['./entities/*.entity.ts']
错误堆栈
[Unhandled promise rejection: EntityMetadataNotFoundError: No metadata for "User" was found.]
at http://192.168.2.2:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&strict=false&minify=false:166214:321 in _createSuperInternal
at node_modules/typeorm/browser/error/TypeORMError.js:5:25 in constructor
at http://192.168.2.2:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&strict=false&minify=false:167099:321 in _createSuperInternal
at node_modules/typeorm/browser/error/EntityMetadataNotFoundError.js:5:24 in constructor
at node_modules/typeorm/browser/data-source/DataSource.js:281:8 in getMetadata
at node_modules/typeorm/browser/repository/Repository.js:19:19 in get__metadata
at node_modules/typeorm/browser/repository/Repository.js:72:9 in save
at App.tsx:31:18 in wrapper
at App.tsx:25:8 in wrapper
at App.tsx:33:15 in useEffect$argument_0
at node_modules/react-native/Libraries/ReactNative/renderApplication.js:58:4 in renderApplication
at node_modules/react-native/Libraries/ReactNative/AppRegistry.js:117:25 in runnables.appKey.run
at node_modules/react-native/Libraries/ReactNative/AppRegistry.js:202:4 in runApplication
import { Entity, PrimaryGeneratedColumn, Column, BaseEntity } from "typeorm"
@Entity('user')
export class User extends BaseEntity {
@PrimaryGeneratedColumn()
id: number
@Column()
firstName: string
@Column()
lastName: string
@Column()
age: number
}
import "reflect-metadata"
import * as SQLite from 'expo-sqlite'
import { DataSource, DataSourceOptions } from "typeorm/browser"
import { User } from "./entities/User.entity"
export const AppDataSourceOptions: DataSourceOptions = {
type: 'expo',
database: 'zipzop.db',
driver: SQLite,
synchronize: true,
logging: false,
entities: [User],
migrations: [],
subscribers: [],
}
export const AppDataSource = new DataSource(AppDataSourceOptions)
import React, { useEffect } from 'react';
import { StatusBar } from 'expo-status-bar';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import useCachedResources from './src/hooks/useCachedResources';
import useColorScheme from './src/hooks/useColorScheme';
import Navigation from './src/navigation';
import { AppDataSource } from './src/database/config';
import { User } from './src/database/entities/User.entity'
export default function App(props : any) {
useEffect(() => {
if(!AppDataSource.isInitialized){
AppDataSource.initialize()
.then(() => console.log("Database initialization SUCESS"))
.catch((err) => console.log("Database initialization FAILED", err))
.finally(async () => {
})
} else {
console.log("Database initialization ALREADY")
}
async function wrapper() {
let repository = AppDataSource.getRepository(User)
let user = new User()
user.firstName = "Francisco"
user.lastName = "Pena"
user.age = 24
await repository.save(user)
}
wrapper()
async function wrapper2() {
let repository = AppDataSource.getRepository(User)
const allUsers = await repository.find()
console.log(allUsers)
}
})
const isLoadingComplete = useCachedResources();
const colorScheme = useColorScheme();
if (!isLoadingComplete) {
return null;
} else {
return (
<SafeAreaProvider>
<Navigation colorScheme={colorScheme} />
<StatusBar />
</SafeAreaProvider>
);
}
}
Repository 错误
我遇到了同样的问题,看看https://github.com/typeorm/expo-example/pull/5
typeorm 的 expo-example 刚刚更新
我正在尝试通过驱动程序 expo-sqlite 在 expo 项目上使用 typeorm,但我一直卡在这个元数据 EntityMetadataNotFoundError: No metadata for "User" was found.
错误上。据我所知,config.ts
上的这一行 entities: [User]
与错误有关,搜索它我发现了一些 people discussing bad configuration on entities, but they are pointing directly to the filesystem path, and I'm passing through the DataSource the User class. I wrote this code based on This repo and TypeORM strange? example
我已经试过了:
entities: ['./entities/*.entity.ts']
错误堆栈
[Unhandled promise rejection: EntityMetadataNotFoundError: No metadata for "User" was found.]
at http://192.168.2.2:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&strict=false&minify=false:166214:321 in _createSuperInternal
at node_modules/typeorm/browser/error/TypeORMError.js:5:25 in constructor
at http://192.168.2.2:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&strict=false&minify=false:167099:321 in _createSuperInternal
at node_modules/typeorm/browser/error/EntityMetadataNotFoundError.js:5:24 in constructor
at node_modules/typeorm/browser/data-source/DataSource.js:281:8 in getMetadata
at node_modules/typeorm/browser/repository/Repository.js:19:19 in get__metadata
at node_modules/typeorm/browser/repository/Repository.js:72:9 in save
at App.tsx:31:18 in wrapper
at App.tsx:25:8 in wrapper
at App.tsx:33:15 in useEffect$argument_0
at node_modules/react-native/Libraries/ReactNative/renderApplication.js:58:4 in renderApplication
at node_modules/react-native/Libraries/ReactNative/AppRegistry.js:117:25 in runnables.appKey.run
at node_modules/react-native/Libraries/ReactNative/AppRegistry.js:202:4 in runApplication
import { Entity, PrimaryGeneratedColumn, Column, BaseEntity } from "typeorm"
@Entity('user')
export class User extends BaseEntity {
@PrimaryGeneratedColumn()
id: number
@Column()
firstName: string
@Column()
lastName: string
@Column()
age: number
}
import "reflect-metadata"
import * as SQLite from 'expo-sqlite'
import { DataSource, DataSourceOptions } from "typeorm/browser"
import { User } from "./entities/User.entity"
export const AppDataSourceOptions: DataSourceOptions = {
type: 'expo',
database: 'zipzop.db',
driver: SQLite,
synchronize: true,
logging: false,
entities: [User],
migrations: [],
subscribers: [],
}
export const AppDataSource = new DataSource(AppDataSourceOptions)
import React, { useEffect } from 'react';
import { StatusBar } from 'expo-status-bar';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import useCachedResources from './src/hooks/useCachedResources';
import useColorScheme from './src/hooks/useColorScheme';
import Navigation from './src/navigation';
import { AppDataSource } from './src/database/config';
import { User } from './src/database/entities/User.entity'
export default function App(props : any) {
useEffect(() => {
if(!AppDataSource.isInitialized){
AppDataSource.initialize()
.then(() => console.log("Database initialization SUCESS"))
.catch((err) => console.log("Database initialization FAILED", err))
.finally(async () => {
})
} else {
console.log("Database initialization ALREADY")
}
async function wrapper() {
let repository = AppDataSource.getRepository(User)
let user = new User()
user.firstName = "Francisco"
user.lastName = "Pena"
user.age = 24
await repository.save(user)
}
wrapper()
async function wrapper2() {
let repository = AppDataSource.getRepository(User)
const allUsers = await repository.find()
console.log(allUsers)
}
})
const isLoadingComplete = useCachedResources();
const colorScheme = useColorScheme();
if (!isLoadingComplete) {
return null;
} else {
return (
<SafeAreaProvider>
<Navigation colorScheme={colorScheme} />
<StatusBar />
</SafeAreaProvider>
);
}
}
Repository 错误
我遇到了同样的问题,看看https://github.com/typeorm/expo-example/pull/5
typeorm 的 expo-example 刚刚更新