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
'use strict'; | |
var defaultEnvConfig = require('./default'); | |
module.exports = { | |
db: { | |
uri: process.env.MONGOHQ_URL || process.env.MONGODB_URI || 'mongodb://' + (process.env.DB_1_PORT_27017_TCP_ADDR || 'localhost') + '/mean-dev', | |
options: {}, | |
// Enable mongoose debug mode | |
debug: process.env.MONGODB_DEBUG || false |
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
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, |
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
import 'dart:convert'; | |
import 'package:best_db_poc/service/model_ctrl/user_model_ctrl.dart'; | |
import 'package:best_db_poc/utils/app_keys.dart'; | |
class UserModel { | |
String gender; | |
_Name name; | |
_Location location; | |
String email; |
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
import 'package:sqflite/sqflite.dart'; | |
import 'package:path/path.dart'; | |
class AppSqliteDb { | |
static Database sqliteDb; | |
static String sqliteDbName = 'db1.db'; | |
static Future init() async { | |
String databasesPath = await getDatabasesPath(); | |
String userDBPath = join(databasesPath, '$sqliteDbName'); | |
sqliteDb = await openDatabase( |
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
Map<String, dynamic> toDb() { | |
return { | |
'name_title': name.title, | |
'name_first': name.first, | |
'name_last': name.last, | |
'location_street_name': location.street.name, | |
'location_street_number': location.street.number.toString(), | |
'location_city': location.city, | |
'location_state': location.state, | |
'location_country': location.country, |
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
static Future initialDownload() async { | |
var response = await AppApi.get<Map<String, dynamic>>(AppUrls.getUsers); | |
if (response.statusCode == 200) { | |
List data = response.data['results']; | |
var saveStartTime = DateTime.now().millisecondsSinceEpoch; | |
for (var rawUser in data) { | |
var user = UserModel.fromMap(rawUser); | |
await AppSqliteDb.sqliteDb.insert(UserModel.tableName, user.toDb()); | |
} | |
var saveEndTime = DateTime.now().millisecondsSinceEpoch; |
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
static Future<List<UserModel>> getAll() async { | |
var fetchStartTime = DateTime.now().millisecondsSinceEpoch; | |
var rawUsers = await AppSqliteDb.sqliteDb.query(UserModel.tableName); | |
var fetchEndTime = DateTime.now().millisecondsSinceEpoch; | |
appWarning( | |
'Time taken to fetch 1000 users from db: ${fetchEndTime - fetchStartTime}ms'); | |
return rawUsers.map((snap) => UserModel.fromDb(snap)).toList(); | |
} |
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
class AppHiveDb { | |
AppHiveDb._(); | |
static AppHiveDb instance = AppHiveDb._(); | |
Box<UserModel> userBox; | |
Box shared; | |
Future init() async { | |
var _directory = await getApplicationDocumentsDirectory(); | |
Hive | |
..init(_directory.path) |
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
import 'dart:convert'; | |
import 'package:best_db_poc/utils/app_keys.dart'; | |
import 'package:hive/hive.dart'; | |
part 'user_model.g.dart'; | |
@HiveType(typeId: 1) | |
class UserModel { | |
@HiveField(0) | |
String gender; |
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
class UserModelCtrl { | |
static Future initialDownload() async { | |
var response = await AppApi.get<Map<String, dynamic>>(AppUrls.getUsers); | |
if (response.statusCode == 200) { | |
List data = response.data['results']; | |
var saveStartTime = DateTime.now().millisecondsSinceEpoch; | |
for (var rawUser in data) { | |
var user = UserModel.fromMap(rawUser); |
OlderNewer