MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / InitSQLite

Function InitSQLite

IceFireDB-SQLite/internal/sqlite/db.go:24–60  ·  view source on GitHub ↗
(ctx context.Context, filename string)

Source from the content-addressed store, hash-verified

22)
23
24func InitSQLite(ctx context.Context, filename string) *sql.DB {
25 var err error
26 // var driver sqlite3.SQLiteDriver
27 // conn, err := driver.Open(filename)
28 db, err = sql.Open("sqlite3", filename)
29 if err != nil {
30 panic(err)
31 }
32 if config.Get().P2P.Enable {
33 // create p2p element
34 p2pHost = p2p.NewP2P(config.Get().P2P.ServiceDiscoveryID,
35 config.Get().P2P.NodeHostIP,
36 config.Get().P2P.NodeHostPort)
37
38 logrus.Info("Completed P2P Setup")
39
40 // Connect to peers with the chosen discovery method
41 switch strings.ToLower(config.Get().P2P.ServiceDiscoverMode) {
42 case "announce":
43 p2pHost.AnnounceConnect() // KadDHT p2p net create
44 case "advertise":
45 p2pHost.AdvertiseConnect()
46 default:
47 p2pHost.AdvertiseConnect()
48 }
49
50 logrus.Info("Connected to P2P Service Peers")
51 var err error
52 p2pPubSub, err = p2p.JoinPubSub(p2pHost, "icefiredb-sqlite-client", config.Get().P2P.ServiceCommandTopic)
53 if err != nil {
54 panic(err)
55 }
56 logrus.Infof("Successfully joined [%s] P2P channel. \n", config.Get().P2P.ServiceCommandTopic)
57 asyncSQL(ctx)
58 }
59 return db
60}
61
62var DMLSQL = []string{
63 "BEGIN",

Callers 4

RunMethod · 0.92
TestSQLiteIntegrationFunction · 0.85
TestErrorHandlingFunction · 0.85

Calls 7

GetFunction · 0.92
NewP2PFunction · 0.92
JoinPubSubFunction · 0.92
asyncSQLFunction · 0.70
OpenMethod · 0.45
AnnounceConnectMethod · 0.45
AdvertiseConnectMethod · 0.45

Tested by 3

TestSQLiteIntegrationFunction · 0.68
TestErrorHandlingFunction · 0.68