2024-06-24 17:48:33 +08:00

102 lines
3.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright © 2023 OpenIM SDK. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build js && wasm
// +build js,wasm
package indexdb
import (
"context"
"github.com/openimsdk/openim-sdk-core/v3/wasm/exec"
)
//1,使用wasm原生的方式tinygo应用于go的嵌入式领域支持的功能有限支持go语言的子集,甚至json序列化都无法支持
//2.函数命名遵从驼峰命名
//3.提供的sql生成语句中关于bool值需要特殊处理create语句的设计的到bool值的需要在创建语句中单独说明这是因为在原有的sqlite中并不支持bool用整数1或者0替代gorm对其做了转换。
//4.提供的sql生成语句中字段名是下划线方式 例如recv_id但是接口转换的数据json tag字段的风格是recvID类似的所有的字段需要做个map映射
//5.任何涉及到gorm获取的是否需要返回错误比如take和find都需要在文档上说明
//6.任何涉及到update的操作一定要看gorm原型中实现如果有select(*)则不需要用temp_struct中的结构体
//7.任何和接口重名的时候db接口统一加上后缀DB
//8.任何map类型统一使用json字符串转换文档说明
type IndexDB struct {
LocalUsers
LocalConversations
*LocalChatLogs
LocalSuperGroupChatLogs
LocalSuperGroup
LocalConversationUnreadMessages
LocalGroups
LocalGroupMember
LocalGroupRequest
LocalCacheMessage
LocalStrangers
LocalUserCommand
*FriendRequest
*Black
*Friend
LocalChatLogReactionExtensions
loginUserID string
}
func (i IndexDB) Close(ctx context.Context) error {
_, err := exec.Exec()
return err
}
func (i IndexDB) InitDB(ctx context.Context, userID string, dataDir string) error {
_, err := exec.Exec(userID, dataDir)
return err
}
func (i IndexDB) SetChatLogFailedStatus(ctx context.Context) {
//msgList, err := i.GetSendingMessageList()
//if err != nil {
// log.Error("", "GetSendingMessageList failed ", err.Error())
// return
//}
//for _, v := range msgList {
// v.Status = constant.MsgStatusSendFailed
// err := i.UpdateMessage(v)
// if err != nil {
// log.Error("", "UpdateMessage failed ", err.Error(), v)
// continue
// }
//}
//groupIDList, err := i.GetReadDiffusionGroupIDList()
//if err != nil {
// log.Error("", "GetReadDiffusionGroupIDList failed ", err.Error())
// return
//}
//for _, v := range groupIDList {
// msgList, err := i.SuperGroupGetSendingMessageList(v)
// if err != nil {
// log.Error("", "GetSendingMessageList failed ", err.Error())
// return
// }
// if len(msgList) > 0 {
// for _, v := range msgList {
// v.Status = constant.MsgStatusSendFailed
// err := i.SuperGroupUpdateMessage(v)
// if err != nil {
// log.Error("", "UpdateMessage failed ", err.Error(), v)
// continue
// }
// }
// }
//
//}
}