Follow

How do you persist a custom object to a database and get it back in JavaScript? With JSDB:

const JSDB = require('@small-tech/jsdb')

class Person {
constructor (name = 'Jane Doe') {
this.name = name
}
introduceYourself () {
console.log(`Hello, I’m ${this.name}.`)
}
}

const db = JSDB.open('db')

if (!db.people) {
db.people = [ new Person('Aral') ]
}

db.people[0].introduceYourself()

// Outputs: Hello, I’m Aral.

github.com/small-tech/jsdb

· · Web · 0 · 1 · 6
Sign in to participate in the conversation
Aral’s Mastodon

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!