dbcontext
v1.0.4
Published
A simple database context for node.js
Downloads
334
Maintainers
Readme
dbcontext - A simple database context for node.js [Discord]
A simple database context for node.js
Installation
npm install --save dbcontext
Usage
import { DbContext, DbSet } from "dbcontext";
interface User {
id: number;
name: string;
age: number;
}
interface Book {
id: number;
title: string;
}
class AppDbContext extends DbContext {
constructor() {
super();
}
users = new DbSet<User>("users");
books = new DbSet<Book>("books");
}
const appDbContext = new AppDbContext(); // or new AppDbContext("./database.json");
// Get all Users
let users = appDbContext.users.ToArray();
console.log(users);
// Get all Books
let books = appDbContext.books.ToArray();
console.log(books);
// Add a new user
appDbContext.users.Add({
id: 1,
name: "John Doe",
age: 25,
});
// Add a new book
appDbContext.books.Add({
id: 1,
title: "The Lord of the Rings",
});
console.log(appDbContext.users.ToArray());
console.log(appDbContext.books.ToArray());