Mock Adapter
Mock Adapter is a simple in-memory adapter for URPC that provides temporary data storage during application runtime. It's perfect for testing, prototyping, and development scenarios where you don't need persistent data storage.
Basic Usage
import { UserEntity } from "./entities/user";
import { repo, URPC } from "@unilab/urpc";
import { MockAdapter } from "@unilab/urpc-adapters";
const MyPlugin = {
entities: [UserEntity],
};
URPC.init({
plugins: [MyPlugin],
entityConfigs: {
user: {
defaultSource: "mock",
},
},
globalAdapters: [
{
source: "mock",
factory: () => new MockAdapter(),
},
],
});Creating Data
async function createUser() {
await repo<UserEntity>({
entity: "user",
}).create({
data: {
id: "1",
name: "John Doe",
email: "[email protected]",
avatar: "https://example.com/avatar.png",
},
});
}Querying Data
async function getUsers() {
const users = await repo({
entity: "user",
}).findMany();
console.log("All users:", users);
}Memory Adapter
Memory Adapter is a lightweight in-memory storage adapter for URPC that stores data directly in application memory. It's perfect for development, testing, and scenarios where you need temporary data storage without persistence.
Relations
Relations in URPC allow you to define connections between different entities using flexible callback functions. This approach enables you to query related data in a single request with complete control over the relation logic.