【发布时间】:2022-08-05 15:13:59
【问题描述】:
我想知道为什么下面的代码块返回整个数据库对象?
const getChatListFromDatabase = async () => {
try {
const chatList = await database.collections
.get(\"chatList\")
.query()
.fetch();
return chatList;
} catch (e) {
console.log(e);
}
};
useEffect(() => {
// prettier-ignore
(
async () => {
const list = await getChatListFromDatabase();
console.log(\"the list is : \", list)
}
)()
});
聊天列表和列表包含数据库对象而不是所有记录。 我想知道我是否写错了查询或者我错过了其他东西。
以下是查询返回的对象:
the list is : Array [
ChatListModel {
\"__changes\": BehaviorSubject {
\"_value\": [Circular],
\"closed\": false,
\"hasError\": false,
\"isStopped\": false,
\"observers\": Array [],
\"thrownError\": null,
},
\"_isEditing\": false,
\"_preparedState\": null,
\"_raw\": Object {
\"_changed\": \"\",
\"_status\": \"created\",
\"email\": \"qwe@asd.com\",
\"id\": \"j9lumqrj3cf5usat\",
\"lastMessage\": \"bro this works\",
\"messageStatus\": \"sent\",
\"profileImageUrl\": \"https://i.pinimg.com/564x/86/6f/2e/866f2ec93c7c05560a76fbbbc470e161.jpg\",
\"time\": \"12:34\",
\"userId\": \"62041ac4cb15d7549f0e61f7\",
\"username\": \"qwe\",
},
\"_subscribers\": Array [],
\"collection\": Collection {
\"_cache\": RecordCache {
\"_debugCollection\": [Circular],
\"map\": Map {
\"j9lumqrj3cf5usat\" => [Circular],
},
\"recordInsantiator\": [Function anonymous],
\"tableName\": \"chatList\",
},
\"_subscribers\": Array [],
\"changes\": Subject {
\"closed\": false,
\"hasError\": false,
\"isStopped\": false,
\"observers\": Array [],
\"thrownError\": null,
},
\"database\": Database {
\"_isBeingReset\": false,
\"_isBroken\": false,
\"_resetCount\": 0,
\"_subscribers\": Array [],
\"_workQueue\": WorkQueue {
\"_db\": [Circular],
\"_queue\": Array [],
\"_subActionIncoming\": false,
},
\"adapter\": DatabaseAdapterCompat {
\"underlyingAdapter\": SQLiteAdapter {
\"_dbName\": \"dbHello\",
\"_dispatcher\": SqliteNativeModulesDispatcher {
\"_tag\": 1,
},
\"_dispatcherType\": \"asynchronous\",
\"_initPromise\": Promise {
\"_U\": 0,
\"_V\": 1,
\"_W\": undefined,
\"_X\": null,
},
\"_migrationEvents\": undefined,
\"_tag\": 1,
\"migrations\": undefined,
\"schema\": Object {
\"tables\": Object {
\"chatList\": Object {
\"columnArray\": Array [
Object {
\"name\": \"userId\",
\"type\": \"string\",
},
Object {
\"name\": \"username\",
\"type\": \"string\",
},
Object {
\"name\": \"email\",
\"type\": \"string\",
},
Object {
\"name\": \"lastMessage\",
\"type\": \"string\",
},
Object {
\"name\": \"time\",
\"type\": \"string\",
},
Object {
\"name\": \"messageStatus\",
\"type\": \"string\",
},
Object {
\"name\": \"profileImageUrl\",
\"type\": \"string\",
},
],
\"columns\": Object {
\"email\": Object {
\"name\": \"email\",
\"type\": \"string\",
},
\"lastMessage\": Object {
\"name\": \"lastMessage\",
\"type\": \"string\",
},
\"messageStatus\": Object {
\"name\": \"messageStatus\",
\"type\": \"string\",
},
\"profileImageUrl\": Object {
\"name\": \"profileImageUrl\",
\"type\": \"string\",
},
\"time\": Object {
\"name\": \"time\",
\"type\": \"string\",
},
\"userId\": Object {
\"name\": \"userId\",
\"type\": \"string\",
},
\"username\": Object {
\"name\": \"username\",
\"type\": \"string\",
},
},
\"name\": \"chatList\",
\"unsafeSql\": undefined,
},
},
\"unsafeSql\": undefined,
\"version\": 1,
},
},
},
\"collections\": CollectionMap {
\"map\": Object {
\"chatList\": [Circular],
},
},
\"schema\": Object {
\"tables\": Object {
\"chatList\": Object {
\"columnArray\": Array [
Object {
\"name\": \"userId\",
\"type\": \"string\",
},
Object {
\"name\": \"username\",
\"type\": \"string\",
},
Object {
\"name\": \"email\",
\"type\": \"string\",
},
Object {
\"name\": \"lastMessage\",
\"type\": \"string\",
},
Object {
\"name\": \"time\",
\"type\": \"string\",
},
Object {
\"name\": \"messageStatus\",
\"type\": \"string\",
},
Object {
\"name\": \"profileImageUrl\",
\"type\": \"string\",
},
],
\"columns\": Object {
\"email\": Object {
\"name\": \"email\",
\"type\": \"string\",
},
\"lastMessage\": Object {
\"name\": \"lastMessage\",
\"type\": \"string\",
},
\"messageStatus\": Object {
\"name\": \"messageStatus\",
\"type\": \"string\",
},
\"profileImageUrl\": Object {
\"name\": \"profileImageUrl\",
\"type\": \"string\",
},
\"time\": Object {
\"name\": \"time\",
\"type\": \"string\",
},
\"userId\": Object {
\"name\": \"userId\",
\"type\": \"string\",
},
\"username\": Object {
\"name\": \"username\",
\"type\": \"string\",
},
},
\"name\": \"chatList\",
\"unsafeSql\": undefined,
},
},
\"unsafeSql\": undefined,
\"version\": 1,
},
},
\"modelClass\": [Function ChatListModel],
},
},
]
-
你解决了吗?
标签: database react-native sqlite watermelondb