Comments (8)
when you do:
const acc = await this.props.database.collections.get('accounts').create(account => {
account.name = this.state.name;
account.initialBalance = 0.0;
account.currency = this.state.currency;
})
try console.log(acc._raw)
. Does it say what you'd expect?
from watermelondb.
that's a good idea, I have not thought about that. No it's full of empty values.
I've even tried to give static values to it to test but it did not work.
this code:
let acc = await this.props.database.collections.get('accounts').create(account => {
account.name = 'test';
account.initialBalance = 0.1;
account.currency = 'currency';
});
console.log(acc._raw);
is producing this log:
10-22 22:21:00.711 16572 18068 I ReactNativeJS: { id: '4zup0vsrn0lxklue',
10-22 22:21:00.711 16572 18068 I ReactNativeJS: _status: 'created',
10-22 22:21:00.711 16572 18068 I ReactNativeJS: _changed: '',
10-22 22:21:00.711 16572 18068 I ReactNativeJS: last_modified: null,
10-22 22:21:00.711 16572 18068 I ReactNativeJS: name: '',
10-22 22:21:00.711 16572 18068 I ReactNativeJS: initial_balance: 0,
10-22 22:21:00.711 16572 18068 I ReactNativeJS: computed_balance: 0,
10-22 22:21:00.711 16572 18068 I ReactNativeJS: currency: '' }
That's what I don't get, the values are obviously recorded since on the view with the observable it works but because it's not saved properly, as soon as I reload the app I just get blank records.
from watermelondb.
OK, I think I know what this is. I think you have misconfigured decorators support in your Babel config file. When you set account.name = 'x'
, you literally set account.name
instead of calling the utter that will update account._raw.name
Have you gone through Installation guide step by step? Do you have the "legacy" option for decorators set to true?
from watermelondb.
Yes indeed you were right, I have something wrong setup in the babelrc, I close the issue :)
Thanks a lot! :)
from watermelondb.
@alex-min facing same issue can you show me your codes
from watermelondb.
Please see #207 (comment)
I had
{
"presets": ["module:metro-react-native-babel-preset"],
"plugins": [
["@babel/plugin-transform-flow-strip-types"],
["@babel/plugin-proposal-decorators", { "legacy": true }]
]
}
instead of
{
"presets": ["module:metro-react-native-babel-preset"],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-transform-runtime", {
"helpers": true,
"regenerator": false
}]
]
}
in my babelrc.
from watermelondb.
I had this issue too.
Need to move export default
to bottom of file:
import { Model } from '@nozbe/watermelondb'
import { field } from '@nozbe/watermelondb/decorators'
export default class User extends Model {
static table = 'users'
@field('email') email
@field('phone') phone
@field('last_name') lastName
@field('first_name') firstName
@field('middle_name') middleName
}
==>
import { Model } from '@nozbe/watermelondb'
import { field } from '@nozbe/watermelondb/decorators'
class User extends Model {
static table = 'users'
@field('email') email
@field('phone') phone
@field('last_name') lastName
@field('first_name') firstName
@field('middle_name') middleName
}
export default User
from watermelondb.
I'm also running into this.
schema
import { appSchema, tableSchema } from '@nozbe/watermelondb';
export const schema = appSchema({
version: 5,
tables: [
tableSchema({
name: 'wallet',
columns: [
{ name: 'walletId', type: 'string', isIndexed: true },
{ name: 'currencyCodeStr', type: 'string', isIndexed: true },
],
}),
],
});
Model
import { Model } from '@nozbe/watermelondb';
import { field } from '@nozbe/watermelondb/decorators';
export class WalletWMO extends Model {
static table = 'wallet';
@field('walletId')
walletId!: string;
@field('currencyCodeStr')
currencyCodeStr!: string;
}
Code to insert
database.write(async () => {
const table = database.get<WalletWMO>('wallet');
const result = await table.create((record: WalletWMO) => {
record.walletId = this.id;
record.currencyCodeStr = this.currencyCode.rawValue;
};);
});
And yet, the underlying `_raw values are empty/default
Tsconfig has
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
BabelConfig has
const plugins = [
'react-hot-loader/babel',
['@babel/plugin-proposal-private-methods', { loose: true }],
['@babel/plugin-proposal-private-property-in-object', { loose: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-proposal-decorators', { legacy: true }],
[
'@babel/plugin-transform-runtime',
{
helpers: true,
regenerator: true,
},
],
]
from watermelondb.
Related Issues (20)
- Is it possible to execute multiple queries in a single statement ? HOT 1
- Module '"@nozbe/watermelondb/decorators"' has no exported member 'experimentalFailsafe'.
- "Invariant Violation: Calling synchronous methods on native modules is not supported in Chrome"
- SyncPullStrategy should associate with table instead of sync
- TimeStamp HOT 2
- Local Storage API - Add support for db.localstorage.key() to fetch all key at runtime
- [question] How to install extensions
- Web Bundling failed
- TypeError: Super expression must either be null or a function HOT 2
- Can we get current migration versions like fromVersion and toVersion
- Different between using `@lazy` decorator vs getter?
- Support for Expo SDK50 HOT 1
- Error: [withObservable] Value passed to withObservables doesn't appear to be observable. See console for details
- Observer with pagination not working
- Unable to resolve module ./internal/operators/timeout from E:\eventual-mvp-app\node_modules\rxjs\dist\cjs\index.js:
- Installation guide HOT 1
- Sync pull HOT 1
- Unable to run between query Because number field in schema treated as string in SQLite DB HOT 2
- Unable to use sortBy option for joining table with use of clause HOT 1
- Unable to push sync TypeError: Cannot read property 'type' of undefined at _setRaw HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from watermelondb.