Reputation:
We are using a Spring-Boot Spring-Data backend that utilizes JPARepositories with the @RepositoryRestResource
annotation. We would like to administer the tables in these repositories (e.g. CRUD) through a javascript frontend without having to go through the work of coding it up. We investigated various alternatives such as LightAdmin, JHipster and ng-admin.
We could not get LightAdmin to work because it relies on a much older version of Spring-Data than what we are running. It is not compatible with the latest and greatest Spring-Data release.
We tried JHipster, but it scaffolds up all the services and controllers which we do not want because @RepositoryRestResource gives that to you for free.
We tried to use ng-admin, but it does not work to well in the context of HATEOAS; we had to put in far too many mappings to get it to only partially work.
So my question is this. Is there a product out that that is similar to ng-admin, JHipster and LightAdmin that will allow us to easily CRUD our @RepositoryRestResource
JPA repositories such that we don't have to write boilerplate CRUD code?
Upvotes: 5
Views: 867
Reputation: 1
may be you can use my awesome code :
db.js
const sqlite3 = require("sqlite3").verbose()
const db = new sqlite3.Database("./book.db")
module.exports = db
setup.js
const db = require("./db.js")
const query = [
`
CREATE TABLE IF NOT EXISTS
contacts (
contactID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
name TEXT,
company TEXT,
telephone TEXT,
email TEXT UNIQUE
)`,
`
CREATE TABLE IF NOT EXISTS
groups (
groupID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
name TEXT
)`,
`
CREATE TABLE IF NOT EXISTS
group_contacts (
group_contactsID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
contactID INTEGER NOT NULL,
groupID INTEGER NOT NULL,
FOREIGN KEY(contactID) REFERENCES contacts(contactID),
FOREIGN KEY(groupID) REFERENCES groups(groupID)
)`
]
for (let i = 0; i < query.length; i++){
db.run(query[i], (err) =>{
console.log(err)
})
}
index.js
const controller = require("./controller.js")
let input = process.argv.slice(2)
let cmd = input[0]
let data = input.slice(1)
switch(cmd){
case "createContact":
controller.createContact(data)
break
controller.js
const contact = require("./model/contact.js")
const group = require("./model/group.js")
const groupContact = require("./model/contact-group.js")
const view = require("./view.js")
class Controller{
static createContact(data){
contact.create(data, (err, output) => {
if (err){
view.createError(err)
} else {
view.createSuccess(output)
}
})
}
static readContact(data){
contact.read(data, (err, output) => {
if (err){
view.readError(err)
} else {
view.readSuccess(output)
}
})
}
static updateContact(data){
contact.update(data, (err) => {
if (err){
view.updateError(err)
} else {
view.updateSuccess(data)
}
})
}
static deleteContact(data){
contact.delete(data, (err) => {
if (err){
view.deleteError(err)
} else {
view.deleteSuccess(data[0])
}
})
}
}
module.exports = Controller
model.js
const db = require("../db.js")
class Contact{
constructor(name, company, phone, email){
this.name = name
this.company = company
this.telephone = phone
this.email = email
}
static create(data, cb){
db.serialize((err) => {
if (err){
cb(err, null)
} else {
let newContact = new Contact(data[0], data[1], data[2], data[3])
let query = `
INSERT INTO contacts (name, company, telephone, email)
VALUES ('${data[0]}', '${data[1]}', '${data[2]}', '${data[3]}')`
db.run(query, (err) => {
if (err){
cb(err, null)
} else {
cb(null, newContact)
}
})
}
})
}
static update(data, cb){
db.serialize((err) => {
if (err){
cb(err, null)
} else {
let query = `
UPDATE contacts SET ${data[1]} = '${data[2]}' WHERE contactID = ${data[0]}`
db.get(query, (err) => {
if (err){
cb(err)
} else {
cb(null)
}
})
}
})
}
static read(data, cb){
db.serialize((err) => {
if (err){
cb(err, null)
} else {
let query = `
SELECT contactID, name, company, telephone, email FROM contacts WHERE contactID = ${data[0]}`
db.get(query, (err, result) => {
if (err){
cb(err, null)
} else {
cb(null, result)
}
})
}
})
}
static delete(data, cb){
db.serialize((err) => {
if (err){
cb(err, null)
} else {
let query = `
DELETE FROM contacts WHERE contactID = ${data[0]}`
db.get(query, (err) => {
if (err){
cb(err)
} else {
cb(null)
}
})
}
})
}
}
module.exports = Contact
view.js
class View {
static createError(err){
console.log(err)
console.log('=====> ERROR')
}
static createSuccess(output){
console.log(output)
console.log('=====> SUCCESS')
}
static readError(err){
console.log(err)
console.log('=====> ERROR')
}
static readSuccess(output){
console.log(output)
console.log('=====> SUCCESS')
}
static updateError(err){
console.log(err)
console.log('=====> ERROR')
}
static updateSuccess(output){
console.log(output)
console.log('=====> SUCCESS')
}
static deleteError(err){
console.log(err)
console.log('=====> ERROR')
}
static deleteSuccess(output){
console.log(output)
console.log('=====> SUCCESS')
}
static undefined(output){
console.log(output)
console.log('=====> UNDEFINED')
}
}
module.exports = View
Upvotes: -1