Skip to content

Commit

Permalink
#2 added local database
Browse files Browse the repository at this point in the history
  • Loading branch information
ctkqiang committed Feb 17, 2023
1 parent 9a467f0 commit fd63535
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 5 deletions.
25 changes: 25 additions & 0 deletions Cryato.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
1A510D252994BBD500F65B0D /* SharedPreferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A510D242994BBD500F65B0D /* SharedPreferences.swift */; };
1A510D282994C07000F65B0D /* SharedPreferenceType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A510D272994C07000F65B0D /* SharedPreferenceType.swift */; };
1A736E34299FB76F001E6921 /* AddRecordsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A736E33299FB76F001E6921 /* AddRecordsView.swift */; };
1A736E3729A00FEC001E6921 /* SQLite in Frameworks */ = {isa = PBXBuildFile; productRef = 1A736E3629A00FEC001E6921 /* SQLite */; };
1A736E3929A0109C001E6921 /* DatabaseManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A736E3829A0109C001E6921 /* DatabaseManager.swift */; };
1A736E3B29A010DA001E6921 /* DBTransactionsRecords.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A736E3A29A010DA001E6921 /* DBTransactionsRecords.swift */; };
1A7B04EC2993D547008D46C3 /* ScannerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A7B04EB2993D547008D46C3 /* ScannerView.swift */; };
1A7B04EE2993E6FB008D46C3 /* RecordsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A7B04ED2993E6FB008D46C3 /* RecordsView.swift */; };
1A7BC4DF299786A70046D622 /* BybitEncryption.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A7BC4DE299786A70046D622 /* BybitEncryption.swift */; };
Expand Down Expand Up @@ -130,6 +133,8 @@
1A510D272994C07000F65B0D /* SharedPreferenceType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedPreferenceType.swift; sourceTree = "<group>"; };
1A510D292994F7B300F65B0D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
1A736E33299FB76F001E6921 /* AddRecordsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddRecordsView.swift; sourceTree = "<group>"; };
1A736E3829A0109C001E6921 /* DatabaseManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseManager.swift; sourceTree = "<group>"; };
1A736E3A29A010DA001E6921 /* DBTransactionsRecords.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DBTransactionsRecords.swift; sourceTree = "<group>"; };
1A7B04EB2993D547008D46C3 /* ScannerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScannerView.swift; sourceTree = "<group>"; };
1A7B04ED2993E6FB008D46C3 /* RecordsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecordsView.swift; sourceTree = "<group>"; };
1A7BC4DE299786A70046D622 /* BybitEncryption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BybitEncryption.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -166,6 +171,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
1A736E3729A00FEC001E6921 /* SQLite in Frameworks */,
1AF58EB4299795D6003BD1DA /* Toast in Frameworks */,
1A0242EB299CBB84005C40BE /* LogToDiscord in Frameworks */,
1A0242E8299CBAAB005C40BE /* SwiftUI-FAB in Frameworks */,
Expand Down Expand Up @@ -207,6 +213,7 @@
1A7BC4E029978BF80046D622 /* DatetimeHelper.swift */,
1A0242DD299BC262005C40BE /* ScamListHandler.swift */,
1A0242EE299E8C74005C40BE /* Helper.swift */,
1A736E3829A0109C001E6921 /* DatabaseManager.swift */,
);
path = Controllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -285,6 +292,7 @@
1A0242C8299986C9005C40BE /* BinanceFundingAccount.swift */,
1A0242D0299B84F8005C40BE /* ScamList.swift */,
1A0242D2299B8880005C40BE /* PaymentMethods.swift */,
1A736E3A29A010DA001E6921 /* DBTransactionsRecords.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -411,6 +419,7 @@
1AF58EB82997A5E7003BD1DA /* AlertToast */,
1A0242E7299CBAAB005C40BE /* SwiftUI-FAB */,
1A0242EA299CBB84005C40BE /* LogToDiscord */,
1A736E3629A00FEC001E6921 /* SQLite */,
);
productName = Cryato;
productReference = 1AD48596298923630024F1AB /* Cryato.app */;
Expand Down Expand Up @@ -491,6 +500,7 @@
1AF58EB72997A5E7003BD1DA /* XCRemoteSwiftPackageReference "AlertToast" */,
1A0242E6299CBAAB005C40BE /* XCRemoteSwiftPackageReference "SwiftUI-FAB" */,
1A0242E9299CBB84005C40BE /* XCRemoteSwiftPackageReference "LogToDiscord" */,
1A736E3529A00FEC001E6921 /* XCRemoteSwiftPackageReference "SQLite.swift" */,
);
productRefGroup = 1AD48597298923630024F1AB /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -554,6 +564,7 @@
buildActionMask = 2147483647;
files = (
1A939050299552F3004AB56D /* Transactions.swift in Sources */,
1A736E3B29A010DA001E6921 /* DBTransactionsRecords.swift in Sources */,
1A1B55D8298A371200C2C773 /* View.swift in Sources */,
1AF58EB629979F34003BD1DA /* String.swift in Sources */,
1A0242D3299B8880005C40BE /* PaymentMethods.swift in Sources */,
Expand All @@ -569,6 +580,7 @@
1A0242DE299BC262005C40BE /* ScamListHandler.swift in Sources */,
1AD4859A298923630024F1AB /* CryatoApp.swift in Sources */,
1A0242D5299B8AF2005C40BE /* Documentation.docc in Sources */,
1A736E3929A0109C001E6921 /* DatabaseManager.swift in Sources */,
1A510D282994C07000F65B0D /* SharedPreferenceType.swift in Sources */,
1A0242C329994837005C40BE /* PNL.swift in Sources */,
1A510D252994BBD500F65B0D /* SharedPreferences.swift in Sources */,
Expand Down Expand Up @@ -958,6 +970,14 @@
kind = branch;
};
};
1A736E3529A00FEC001E6921 /* XCRemoteSwiftPackageReference "SQLite.swift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/stephencelis/SQLite.swift.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.9.2;
};
};
1AF58EB2299795D6003BD1DA /* XCRemoteSwiftPackageReference "Toast-Swift" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/scalessec/Toast-Swift.git";
Expand Down Expand Up @@ -987,6 +1007,11 @@
package = 1A0242E9299CBB84005C40BE /* XCRemoteSwiftPackageReference "LogToDiscord" */;
productName = LogToDiscord;
};
1A736E3629A00FEC001E6921 /* SQLite */ = {
isa = XCSwiftPackageProductDependency;
package = 1A736E3529A00FEC001E6921 /* XCRemoteSwiftPackageReference "SQLite.swift" */;
productName = SQLite;
};
1AF58EB3299795D6003BD1DA /* Toast */ = {
isa = XCSwiftPackageProductDependency;
package = 1AF58EB2299795D6003BD1DA /* XCRemoteSwiftPackageReference "Toast-Swift" */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
"revision" : "967d008563ec0e8a40d6ab07ba88fccf0b35b0da"
}
},
{
"identity" : "sqlite.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/stephencelis/SQLite.swift.git",
"state" : {
"revision" : "7a2e3cd27de56f6d396e84f63beefd0267b55ccb",
"version" : "0.14.1"
}
},
{
"identity" : "swiftui-fab",
"kind" : "remoteSourceControl",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>SQLite (Playground) 1.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>3</integer>
</dict>
<key>SQLite (Playground) 2.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>4</integer>
</dict>
<key>SQLite (Playground).xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>2</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
Expand Down
38 changes: 38 additions & 0 deletions Cryato/Controllers/DatabaseManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Sqlite3.swift
// Cryato
//
// Created by John Melody Me on 18/02/2023.
//

import Foundation

#if canImport(SQLite)
import SQLite
#endif

class DatabaseManager {
private var FILE_NAME :String = "Records.sqlite3"
private var database :Connection!
private var RECORDS :Table!
private var id :Expression<Int64>!
private var dateTime :Expression<String>!
private var unitPurchased :Expression<Int64>!
private var originalPrice :Expression<Double>!
private var sellingPrice :Expression<Double>!

public init() {
do {
let path :String = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first ?? ""

self.database = try Connection("\(path)/\(self.FILE_NAME)")
self.RECORDS = Table("Records")

self.id = Expression<Int64>("id")
self.dateTime = Expression<String>("dateTime")

} catch {
NSLog(error.localizedDescription)
}
}
}
16 changes: 16 additions & 0 deletions Cryato/Models/DBTransactionsRecords.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// DBTransactionsRecords.swift
// Cryato
//
// Created by John Melody Me on 18/02/2023.
//

import Foundation

struct DBTransRecords : Identifiable {
public var id :Int64 = 0
public var dateTime :String = ""
public var unitPurchased :Int64 = 0
public var originalPrice :Double = 0.0
public var sellingPrice :Double = 0.0
}
8 changes: 5 additions & 3 deletions Cryato/Views/AddRecordsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import SwiftUI

struct AddRecordsView: View {
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
public var body: some View {
NavigationView {

}
}
}

struct AddRecordsView_Previews: PreviewProvider {
static var previews: some View {
public static var previews: some View {
AddRecordsView()
}
}
4 changes: 2 additions & 2 deletions Cryato/Views/RecordsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ struct RecordsView: View {
public var body: some View {
NavigationView {
Form {
VStack {
VStack(spacing: 0) {
Text("asdassd")
}
}.ignoresSafeArea()
}
.navigationBarTitle("Records")
.scrollDismissesKeyboard(.interactively)
Expand Down

0 comments on commit fd63535

Please sign in to comment.