本文整理汇总了TypeScript中lokijs.addCollection函数的典型用法代码示例。如果您正苦于以下问题:TypeScript addCollection函数的具体用法?TypeScript addCollection怎么用?TypeScript addCollection使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了addCollection函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
public constructor(getISODate: () => string) {
const db = new loki("stats-database");
this.counters = db.addCollection("counters");
this.customEvents = db.addCollection("customEvents");
this.timings = db.addCollection("timing");
this.getDate = () => getISODate();
}
示例2: onAutoLoad
function onAutoLoad() {
var users = db.getCollection<model.User>("users")
if (!users) {
users = db.addCollection<model.User>("users");
console.log("Database not found. Adding the users collection.");
}
self.users = users;
};
示例3: parse
parse(source: string, filename: string): any {
/*try {
let gherkinDocument = parser.parse(source);
let result = JSON.stringify(gherkinDocument, null, 2);
console.log(result);
} catch (error) {
console.log(error);
}*/
let ending = "\n";
if (source.indexOf("\r\n") > 0) {
ending = "\r\n";
}
let name = path.basename(filename, "feature");
let lines = source.split(ending); // "/\r?\n/");
let arr = [];
let lockdb = new loki("loki.json");
let methods = lockdb.addCollection("ValueTable");
let replReg = new RegExp("'[А-яA-z\d]'", "i");
for (let index = 0; index < lines.length; index++) {
let element: string = lines[index].trim();
if (element.startsWith("#") || element.startsWith("@")) {
continue;
}
if (element.trim().length === 0) { continue; }
element = element.replace(/'[А-яA-z\d]+'/i, "");
let methRow: MethodValue = {
"name": String(element),
"isproc": Boolean(false),
"line": index,
"endline": index,
"context": "",
"_method": {},
"filename": filename,
"module": element,
"description": name
};
methods.insert(methRow);
}
return methods;
}
示例4:
jenkins.listJobs().then(jobs => Promise.map(jobs, job => job.getBuildResults().then(buildResults => {
var jobCollection = db.addCollection(job.name);
buildResults.forEach(buildResult => jobCollection.insert(buildResult));
}).catch(err => {
示例5: Loki
import * as Loki from 'lokijs';
import {Post, User} from '../../client/entities';
export const db = new Loki("q&a.db");
export const post = db.addCollection<Post & { type: "QUESTION" | "ANSWER" | "COMMENT"; }>("post", { indices: ["id"] });
export const postToPosts = db.addCollection<{ parentId: number; childId: number; }>("post_to_post");
export const passport = db.addCollection<{ id: number; login: string; password: string; }>("passport", { indices: ["id", "login"]});
export const user = db.addCollection<User>("user", { indices: ["id"] });
示例6: createBoard
export function createBoard(): Board {
const board = TsEventEmitter.create() as Board
const db = new Loki("")
const rooms = board.rooms = db.addCollection<Room>("rooms", {
unique: ["name"],
indices: ["memberCount"],
})
function connect() {
const peer = TsEventEmitter.create() as Peer
function process(data: string) {
// emit the data for the board to process
board.event("data").emit({ data, peer })
if (data.charAt(0) === "/") {
const command = data.slice(1, data.indexOf("|", 1)).toLowerCase()
// split data and parse the parts
const parts = data.slice(command.length + 2).split("|").map(jsonparse)
switch (command) {
case "to": {
const idPart: IdType = parts[0]
const target = peer.room && peer.room.members.find((member: any) => member.id === idPart)
if (target) {
target.event("data").emit(data)
} else {
console.warn(`got a to request for id "${idPart}" but cannot find target`)
}
return
}
case "leave": {
board.event("leave").emit(peer)
break
}
case "announce": {
board.event("announce").emit({peer, data: parts[1]})
break
}
default: {
console.warn(`dropped "${command}" event from ${parts[0]}`)
}
}
if (peer.room) {
peer.room.members.filter((p: any) => p !== peer).forEach(member => member.event("data").emit(data))
}
}
}
// add peer functions
peer.process = process
peer.leave = () => board.event("leave").emit(peer)
// trigger the peer connect
board.event("peer:connect").emit(peer)
return peer
}
function destroy() {
rooms.clear()
}
function getRoom(name: string): Room {
function getCachedRoom(): Room | null {
return rooms.by("name", name)
}
function createRoom() {
// create a simple room object
const room = rooms.insert({
name,
memberCount: 0,
members: [],
})
board.event("room:create").emit(name)
return room
}
return getCachedRoom() || createRoom()
}
// handle announce messages
board.event("announce").on(({peer, data}: {peer: Peer, data: AnnounceData }) => {
const targetRoom: string | undefined = data && data.room
const room = targetRoom && getRoom(targetRoom)
// a peer can only be in one room at a time
// trigger a leave command if the peer joins a new room
if (peer.room && peer.room.name !== targetRoom) {
board.event("leave").emit(peer)
}
//.........这里部分代码省略.........