Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function cursorToIndexKey(
type,
index,
cursor,
keyPrefix,
paddingSize,
defaultValue,
) {
if (cursor) {
// Valid cursor is always enough, we retrieve the object it points to
// to get between data
return RethinkDB.do(
RethinkDB.table(type).get(cursor.value),
(result) => RethinkDB.branch(
result,
getIndexValue(result, index.fields),
defaultValue
)
);
} else if (keyPrefix) {
// No cursor passed, we create between data from data we already have
// and pad the unavailable values with base (either minval or maxval)
return [
...keyPrefix,
...(new Array(paddingSize).fill(defaultValue)),
];
} else {
return defaultValue;
toReQL(db) {
return RethinkDB.do(db.table(TYPE_TABLE).get(this.name).delete({
returnChanges: true,
}), (result) => {
return RethinkDB.do(db.tableDrop(this.name), () => {
return result('changes')(0)('old_val');
});
});
}
}
export function createType(conn, type) {
if (type.interfaces.includes('Node')) {
return queryWithIDs('ReindexType', RethinkDB.do(
RethinkDB.tableCreate(type.name),
() => getCreateQuery('ReindexType', type)
)).run(conn);
} else {
return create(conn, 'ReindexType', type);
}
}
toReQL(db) {
return RethinkDB.do(
db.table(TYPE_TABLE).get(this.tableName).update((type) => ({
fields: type('fields').difference(
type('fields').filter({name: this.name})
),
indexes: type('indexes').difference(
type('indexes').filter({name: this.name})
),
}), {
returnChanges: true,
}),
db.table(TYPE_TABLE).get(this.targetName).update((type) => ({
fields: type('fields').difference(
type('fields').filter({name: this.reverseName})
),
}), {
returnChanges: true,
export async function getMetadata(conn) {
const result = await RethinkDB.do(
queryWithIDs(TYPE_TABLE, RethinkDB.table(TYPE_TABLE)).coerceTo('array'),
queryWithIDs(INDEX_TABLE, RethinkDB.table(INDEX_TABLE)).coerceTo('array'),
queryWithIDs(HOOK_TABLE, RethinkDB.table(HOOK_TABLE)).coerceTo('array'),
(types, indexes, hooks) => ({
types,
indexes,
hooks,
})
).run(conn);
result.types = result.types.map((type) => {
type.fields = injectDefaultFields(type);
return type;
});
return result;
}
async function main() {
await runMigration([
RethinkDB.do(
RethinkDB.tableList(),
(tables) =>
RethinkDB.branch(
tables.contains('ReindexHook'),
{},
RethinkDB.tableCreate('ReindexHook')
)
),
]);
}
getFieldsAndTypes() {
return this.connection.run(
r.do(r.db(this.database.name).table(this.name).sample(500).coerceTo('array'), rows => {
return rows.concatMap(_row => _row.keys())
.distinct()
.map(field => {
return {
name: field,
types: rows.group(_row => _row(field).default(null).typeOf()).count().ungroup().coerceTo('array')
};
});
})
);
}
}
(result) => RethinkDB.do(
RethinkDB.branch(
result('interfaces').contains('Node'),
RethinkDB.tableDrop(result('name')),
{}
),
() => result
)
)).run(conn);
}), (result) => {
return RethinkDB.do(db.tableDrop(this.name), () => {
return result('changes')(0)('old_val');
});
});
}