React Native: create tables query fails in release mode with query syntax error
See original GitHub issueIssue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[x] react-native
[ ] expo
TypeORM version:
[ ] latest
[ ] @next
[x] 0.2.16
(or put your version here)
Steps to reproduce or a small repository showing the problem:
I only added TypeORM to my project last week. Everything was working great while developing but as soon as I began making release builds of my app the entire database stopped working. Turning on logging shows me this:
2019-04-03 19:08:05.864 [error][tid:com.facebook.react.JavaScript] 'query failed: ', 'CREATE TABLE "temporary_t" ()'
2019-04-03 19:08:05.866 [error][tid:com.facebook.react.JavaScript] 'error: ', { message: 'near ")": syntax error', code: 5 }
I’ve been unable to identify what could be causing this and from a cursory search I haven’t been able to find any other reports of this issue.
I believe the error is being thrown immediately on creation of the database in the root of the app, and no further database related operation work in the application. My initialisation code:
const sqliteConnectionManager = getConnectionManager();
const connection = sqliteConnectionManager.create({
type: 'react-native',
database: DATABASE_NAME,
synchronize: true,
logging: true,
// migrations,
entities,
location: 'default',
});
await connection.connect();
I’m using plain JavaScript in this project, not TypeScript. Any help would be much appreciated.
May also be worth mentioning I’m using ES6 with decorators for defining my entities, like so:
@Entity()
class ReferenceDataGroup {
@PrimaryColumn('text')
groupId;
@Column({ type: 'text', nullable: true })
lastModified;
@OneToMany(() => ReferenceDataValue, rdValue => rdValue.groupId, { eager: false })
values;
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:13 (5 by maintainers)
Top GitHub Comments
Considering my original problem was resolved I suppose this issue can be closed.
Though it may be worth adding a quick but prominent mention in the setup for React Native that when using the decorator pattern for defining entities with ES6 and Babel, explicit table and column names need to be defined if the compiled code is going to be minified. Since minification is on by default in RN projects, I imagine other users may keep running into this issue.
Just a heads up here: I ran into a related issue, but it was caused by the queryBuilder. While minification seems to work for regular queries as the minified aliases would make queries consistent, using the
queryBuilder
with hardcoded strings would break due to the following:The builder would be:
A generated select query would be
which would fail for obvious reasons. The only proper solution is to update minifireConfig via
metro.config.js
, ex: