-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store data in database (TypeORM) #12
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(Many bugs right now because the `state`'s data are not the same format)
So that we can make sure state and database are consistent
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously all the data are stored as
JSON.stringify
string in Async Storage. This PR uses TypeORM with Expo SQLite to store pings data and answers data in the database. Each study will have its own SQLite file, and in the file, there are two tables:ping
andanswer
. Refer toPingEntity
andAnswerEntity
for details.The types
Answer
s are replaced by the classesAnswerEntity
s. The typePingInfo
is replaced byPingEntity
.Async Storage no longer stores
PingInfo
s, but is still used to storeSurveyScreenState
s. It means thatAnswersList
exists both in state (and hence the Async Storage that stores allSurveyScreenState
s) and the database. This decision was based on the following reasons:It means that we get all ping info from the database, get all answers info from the state during the survey, and get all answers info from the database during data upload. Notice that we
.save()
an entry in database first, then.reload()
and save it to the state. This is so that our data in state can match data in database, hence making the code less prone to bugs.For data upload, currently we upload add
PingEntity[]
andAnswerEntity[]
as JSON (Notice this means that the data structure has changed - previous each answer is nested inside a ping, but now all answers are flattened to the same layer and identified by the composite keypingId
andquestionId
). In the future, we might consider directly uploading SQL to the server.This provide basic support for #10.
Note: at the time of merging, there is typeorm/typeorm#6142. It should fix with the next version of TypeORM.