sqlStream => sqlAsync
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4316 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
d904d8922f
commit
2158ad3c0b
@ -1,6 +1,6 @@
|
||||
async function get_apps() {
|
||||
let results = {};
|
||||
await ssb.sqlStream(`
|
||||
await ssb.sqlAsync(`
|
||||
SELECT messages.*
|
||||
FROM messages_fts('"application/tildefriends"')
|
||||
JOIN messages ON messages.rowid = messages_fts.rowid
|
||||
@ -52,4 +52,4 @@ async function main() {
|
||||
`);
|
||||
}
|
||||
|
||||
main();
|
||||
main();
|
||||
|
36
src/ssb.js.c
36
src/ssb.js.c
@ -303,41 +303,6 @@ static JSValue _tf_ssb_closeConnection(JSContext* context, JSValueConst this_val
|
||||
return connection ? JS_TRUE : JS_FALSE;
|
||||
}
|
||||
|
||||
typedef struct _sqlStream_callback_t
|
||||
{
|
||||
JSContext* context;
|
||||
JSValue callback;
|
||||
} sqlStream_callback_t;
|
||||
|
||||
static void _tf_ssb_sqlStream_callback(JSValue row, void* user_data)
|
||||
{
|
||||
sqlStream_callback_t* info = user_data;
|
||||
JSValue response = JS_Call(info->context, info->callback, JS_UNDEFINED, 1, &row);
|
||||
tf_util_report_error(info->context, response);
|
||||
JS_FreeValue(info->context, response);
|
||||
}
|
||||
|
||||
static JSValue _tf_ssb_sqlStream(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv)
|
||||
{
|
||||
JSValue result = JS_NULL;
|
||||
tf_ssb_t* ssb = JS_GetOpaque(this_val, _tf_ssb_classId);
|
||||
if (ssb)
|
||||
{
|
||||
const char* query = JS_ToCString(context, argv[0]);
|
||||
if (query)
|
||||
{
|
||||
sqlStream_callback_t info =
|
||||
{
|
||||
.context = context,
|
||||
.callback = argv[2],
|
||||
};
|
||||
result = tf_ssb_db_visit_query(ssb, query, argv[1], _tf_ssb_sqlStream_callback, &info);
|
||||
JS_FreeCString(context, query);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
typedef struct _sql_work_t
|
||||
{
|
||||
uv_work_t request;
|
||||
@ -1319,7 +1284,6 @@ void tf_ssb_register(JSContext* context, tf_ssb_t* ssb)
|
||||
JS_SetPropertyStr(context, object, "getConnection", JS_NewCFunction(context, _tf_ssb_getConnection, "getConnection", 1));
|
||||
JS_SetPropertyStr(context, object, "closeConnection", JS_NewCFunction(context, _tf_ssb_closeConnection, "closeConnection", 1));
|
||||
JS_SetPropertyStr(context, object, "forgetStoredConnection", JS_NewCFunction(context, _tf_ssb_forgetStoredConnection, "forgetStoredConnection", 1));
|
||||
JS_SetPropertyStr(context, object, "sqlStream", JS_NewCFunction(context, _tf_ssb_sqlStream, "sqlStream", 3));
|
||||
JS_SetPropertyStr(context, object, "sqlAsync", JS_NewCFunction(context, _tf_ssb_sqlAsync, "sqlAsync", 3));
|
||||
JS_SetPropertyStr(context, object, "storeMessage", JS_NewCFunction(context, _tf_ssb_storeMessage, "storeMessage", 1));
|
||||
JS_SetPropertyStr(context, object, "getBroadcasts", JS_NewCFunction(context, _tf_ssb_getBroadcasts, "getBroadcasts", 0));
|
||||
|
Loading…
Reference in New Issue
Block a user