本文整理汇总了TypeScript中eez-studio-shared/db.db类的典型用法代码示例。如果您正苦于以下问题:TypeScript db类的具体用法?TypeScript db怎么用?TypeScript db使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了db类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: insertSource
export function insertSource(instrumentName: string, instrumentExtensionId: string) {
try {
let result = db
.prepare(
`SELECT * FROM
"${notebookItemSourcesStore.storeName}"
WHERE instrumentName = ? AND instrumentExtensionId = ?`
)
.get([instrumentName, instrumentExtensionId]);
const existingSourceId = result && result.id;
if (existingSourceId) {
return existingSourceId;
}
const info = db
.prepare(
`INSERT INTO "notebook/sources" (instrumentName, instrumentExtensionId) VALUES(?, ?)`
)
.run([instrumentName, instrumentExtensionId]);
return info.lastInsertRowid.toString();
} catch (err) {
console.error(err);
}
return null;
}
示例2: constructor
constructor() {
activityLogStore.watch(
{
createObject: (object: any) => {
if (object.type === "activity-log/session-start") {
runInAction(() => {
this.id = object.id;
this.message = object.message;
});
}
},
updateObject: (changes: any) => {
if (changes.id === this.id && changes.message !== undefined) {
try {
const message = JSON.parse(changes.message);
if (message.sessionCloseId) {
runInAction(() => {
this.id = undefined;
this.message = undefined;
});
} else {
runInAction(() => {
this.message = changes.message;
});
}
} catch (err) {
console.error(err);
}
}
},
deleteObject: (object: any) => {
if (object.id === this.id) {
runInAction(() => {
this.id = undefined;
this.message = undefined;
});
}
}
},
{
skipInitialQuery: true
}
);
const result = db
.prepare(
`SELECT
id
FROM
activityLog
WHERE
type = 'activity-log/session-start' AND
json_extract(message, '$.sessionCloseId') IS NULL
ORDER BY date DESC
LIMIT 1`
)
.get();
this.id = result && result.id.toString();
}
示例3: loadData
export function loadData(store: IStore, id: string) {
try {
let result = db.prepare(`SELECT data FROM "${store.storeName}" WHERE id = ?`).get(id);
return result && result.data;
} catch (err) {
console.error(err);
}
return undefined;
}
示例4: getSource
export function getSource(sourceId: string): INotebookItemSource | null {
try {
let source = db
.prepare(`SELECT * FROM "${notebookItemSourcesStore.storeName}" WHERE id = ? `)
.get([sourceId]);
return source;
} catch (err) {
console.error(err);
}
return null;
}
示例5: deleteGroupInShortcuts
export function deleteGroupInShortcuts(groupName: string) {
db.prepare(`DELETE FROM "${store.storeName}" WHERE groupName = ?`).run(groupName);
let changedShortcuts = values(shortcuts)
.filter(shortcut => shortcut.groupName === groupName)
.map(shortcut => ({ id: shortcut.id }));
sendMessage(store.notifySource, {
op: "delete",
object: changedShortcuts
});
}
示例6: async
export default service<Params, Result>("db-services/query", async (inputParams: Params) => {
try {
const rows = db.prepare(inputParams.query).all(...inputParams.args);
return {
err: null,
rows
};
} catch (err) {
return {
err,
rows: []
};
}
});
示例7: insertSourceFromInstrumentId
export function insertSourceFromInstrumentId(instrumentId: string) {
try {
let result = db
.prepare(`SELECT * FROM "${instrumentsStore.storeName}" WHERE id = ?`)
.get([instrumentId]);
if (result && result.id) {
return insertSource(
getInstrumentDescription(result.instrumentExtensionId, result.label, result.idn),
result.instrumentExtensionId
);
}
} catch (err) {
console.error(err);
}
return null;
}
示例8: async
export default service<void, void>("db-services/vacuum", async () => {
db.exec("VACUUM");
});