-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
159 lines (155 loc) · 4.13 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, { Fragment } from 'react';
import { SafeAreaView, View, Button, Alert, StatusBar } from 'react-native';
import {
select,
insert,
insertMany,
insertOrUpdateMany,
deleteOne,
deleteMany,
update,
} from 'hugo-realm-lib';
const App = () => {
return (
<Fragment>
<StatusBar barStyle='dark-content' />
<SafeAreaView
style={{
flex: 3,
justifyContent: 'space-between',
}}
>
<Button
title='Insert'
onPress={() =>
insert(
{
name: 'Hugo',
email: '[email protected]',
address: 'Rua',
},
(res, error) => {
Alert.alert('Inseriu', JSON.stringify(res));
}
)
}
/>
<Button
title='Insert Many'
onPress={() =>
insertMany(
[
{
name: 'Hugo3',
email: '[email protected]',
address: 'Rua',
},
{
name: 'Hugo4',
email: '[email protected]',
address: 'Rua',
},
{ name: 'Hugo5', email: '[email protected]', address: 'Rua' },
],
(res, error) => Alert.alert('Inseriu', JSON.stringify(res))
)
}
/>
<Button
title='Insert Update Many'
onPress={() =>
insertOrUpdateMany(
[
{
name: 'Hugo3',
email: '[email protected]',
address: 'Rua',
},
{
name: 'Hugo4',
email: '[email protected]',
address: 'Rua',
},
{ name: 'Hugo5', email: '[email protected]', address: 'Rua' },
],
(res, error) => Alert.alert('Inseriu', JSON.stringify(res))
)
}
/>
<Button
title='Update'
onPress={() =>
select((res, error) => {
if (res.length) {
update(
{
id: res[0].id,
name: 'Hugo update',
email: '[email protected]',
address: 'Rua',
},
(resUpdate, error) =>
Alert.alert('Atualizou', `ID ${res[0].id} atualizado`)
);
} else {
Alert.alert('Aviso', 'sem itens para atualizar');
}
})
}
/>
<Button
title='Delete'
onPress={() =>
select((res, error) => {
if (res.length) {
deleteOne(res[0].id, (resDel, error) =>
Alert.alert('Apagou', `ID ${res[0].id} apagado`)
);
} else {
Alert.alert('Aviso', 'sem itens para apagar');
}
})
}
/>
<Button
title='Delete Many'
onPress={() =>
select((res, error) => {
if (res.length > 1) {
deleteMany([res[0].id, res[1].id], (resDel, error) =>
Alert.alert(
'Apagou',
`IDs ${res[0].id} e ${res[1].id} apagados`
)
);
} else if (res.length) {
deleteMany([res[0].id], (resDel, error) =>
Alert.alert('Apagou', `ID ${res[0].id} apagado`)
);
} else {
Alert.alert('Aviso', 'sem itens para apagar');
}
})
}
/>
<Button
title='Select'
onPress={() =>
select((res, error) => {
Alert.alert(`Registros: ${res.length}`, JSON.stringify(res));
})
}
/>
</SafeAreaView>
<View style={{ flex: 2 }} />
</Fragment>
);
};
export default App;