I was using RethinkDB in my last project, with JSData because it offers a great and simple API.
Like another DB's, rethinkdb doenst support unique constraints, and the developers comunity are adding a workaround to support this. My suggestion here is add a wrapper the create function with some like this:
const adapter = new RethinkDBAdapter();
(adapter as any).createFn = adapter.create;
adapter.create = async function(mapper, props, opts) {
for (const field of (mapper as any).schema.unique) {
if (!(await (adapter as any).r.table(mapper.name).getAll(props[field], {index: field}).isEmpty()))
throw new Error(`Unique constraint violated on field { ${field}: ${props[field]} }`);
}
return await (adapter as any).createFn(mapper, props, opts);
};
I was using RethinkDB in my last project, with JSData because it offers a great and simple API. Like another DB's, rethinkdb doenst support
unique
constraints, and the developers comunity are adding a workaround to support this. My suggestion here is add a wrapper the create function with some like this: