From fd6353589aa42851d7db939706378dd57833654d Mon Sep 17 00:00:00 2001 From: John Melody Me Date: Sat, 18 Feb 2023 04:00:41 +0800 Subject: [PATCH] #2 added local database --- Cryato.xcodeproj/project.pbxproj | 25 ++++++++++++ .../xcshareddata/swiftpm/Package.resolved | 9 +++++ .../xcschemes/xcschememanagement.plist | 21 ++++++++++ Cryato/Controllers/DatabaseManager.swift | 38 +++++++++++++++++++ Cryato/Models/DBTransactionsRecords.swift | 16 ++++++++ Cryato/Views/AddRecordsView.swift | 8 ++-- Cryato/Views/RecordsView.swift | 4 +- 7 files changed, 116 insertions(+), 5 deletions(-) create mode 100644 Cryato/Controllers/DatabaseManager.swift create mode 100644 Cryato/Models/DBTransactionsRecords.swift diff --git a/Cryato.xcodeproj/project.pbxproj b/Cryato.xcodeproj/project.pbxproj index 691ea35..556d5a4 100644 --- a/Cryato.xcodeproj/project.pbxproj +++ b/Cryato.xcodeproj/project.pbxproj @@ -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 */; }; @@ -130,6 +133,8 @@ 1A510D272994C07000F65B0D /* SharedPreferenceType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharedPreferenceType.swift; sourceTree = ""; }; 1A510D292994F7B300F65B0D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 1A736E33299FB76F001E6921 /* AddRecordsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddRecordsView.swift; sourceTree = ""; }; + 1A736E3829A0109C001E6921 /* DatabaseManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseManager.swift; sourceTree = ""; }; + 1A736E3A29A010DA001E6921 /* DBTransactionsRecords.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DBTransactionsRecords.swift; sourceTree = ""; }; 1A7B04EB2993D547008D46C3 /* ScannerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScannerView.swift; sourceTree = ""; }; 1A7B04ED2993E6FB008D46C3 /* RecordsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecordsView.swift; sourceTree = ""; }; 1A7BC4DE299786A70046D622 /* BybitEncryption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BybitEncryption.swift; sourceTree = ""; }; @@ -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 */, @@ -207,6 +213,7 @@ 1A7BC4E029978BF80046D622 /* DatetimeHelper.swift */, 1A0242DD299BC262005C40BE /* ScamListHandler.swift */, 1A0242EE299E8C74005C40BE /* Helper.swift */, + 1A736E3829A0109C001E6921 /* DatabaseManager.swift */, ); path = Controllers; sourceTree = ""; @@ -285,6 +292,7 @@ 1A0242C8299986C9005C40BE /* BinanceFundingAccount.swift */, 1A0242D0299B84F8005C40BE /* ScamList.swift */, 1A0242D2299B8880005C40BE /* PaymentMethods.swift */, + 1A736E3A29A010DA001E6921 /* DBTransactionsRecords.swift */, ); path = Models; sourceTree = ""; @@ -411,6 +419,7 @@ 1AF58EB82997A5E7003BD1DA /* AlertToast */, 1A0242E7299CBAAB005C40BE /* SwiftUI-FAB */, 1A0242EA299CBB84005C40BE /* LogToDiscord */, + 1A736E3629A00FEC001E6921 /* SQLite */, ); productName = Cryato; productReference = 1AD48596298923630024F1AB /* Cryato.app */; @@ -491,6 +500,7 @@ 1AF58EB72997A5E7003BD1DA /* XCRemoteSwiftPackageReference "AlertToast" */, 1A0242E6299CBAAB005C40BE /* XCRemoteSwiftPackageReference "SwiftUI-FAB" */, 1A0242E9299CBB84005C40BE /* XCRemoteSwiftPackageReference "LogToDiscord" */, + 1A736E3529A00FEC001E6921 /* XCRemoteSwiftPackageReference "SQLite.swift" */, ); productRefGroup = 1AD48597298923630024F1AB /* Products */; projectDirPath = ""; @@ -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 */, @@ -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 */, @@ -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"; @@ -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" */; diff --git a/Cryato.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Cryato.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 729b1e6..bb11f22 100644 --- a/Cryato.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Cryato.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -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", diff --git a/Cryato.xcodeproj/xcuserdata/johnmelodyme.xcuserdatad/xcschemes/xcschememanagement.plist b/Cryato.xcodeproj/xcuserdata/johnmelodyme.xcuserdatad/xcschemes/xcschememanagement.plist index 4a8260a..2d78547 100644 --- a/Cryato.xcodeproj/xcuserdata/johnmelodyme.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/Cryato.xcodeproj/xcuserdata/johnmelodyme.xcuserdatad/xcschemes/xcschememanagement.plist @@ -9,6 +9,27 @@ orderHint 0 + SQLite (Playground) 1.xcscheme + + isShown + + orderHint + 3 + + SQLite (Playground) 2.xcscheme + + isShown + + orderHint + 4 + + SQLite (Playground).xcscheme + + isShown + + orderHint + 2 + SuppressBuildableAutocreation diff --git a/Cryato/Controllers/DatabaseManager.swift b/Cryato/Controllers/DatabaseManager.swift new file mode 100644 index 0000000..e04ef0d --- /dev/null +++ b/Cryato/Controllers/DatabaseManager.swift @@ -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! + private var dateTime :Expression! + private var unitPurchased :Expression! + private var originalPrice :Expression! + private var sellingPrice :Expression! + + 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("id") + self.dateTime = Expression("dateTime") + + } catch { + NSLog(error.localizedDescription) + } + } +} diff --git a/Cryato/Models/DBTransactionsRecords.swift b/Cryato/Models/DBTransactionsRecords.swift new file mode 100644 index 0000000..644aefb --- /dev/null +++ b/Cryato/Models/DBTransactionsRecords.swift @@ -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 +} diff --git a/Cryato/Views/AddRecordsView.swift b/Cryato/Views/AddRecordsView.swift index 85871bd..ee47f7b 100644 --- a/Cryato/Views/AddRecordsView.swift +++ b/Cryato/Views/AddRecordsView.swift @@ -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() } } diff --git a/Cryato/Views/RecordsView.swift b/Cryato/Views/RecordsView.swift index c36bd7a..a9a0452 100644 --- a/Cryato/Views/RecordsView.swift +++ b/Cryato/Views/RecordsView.swift @@ -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)