module.exports = function(User) {
User.show = function(name,lastName) {
console.log(name);
console.log(lastName);
}
User.remoteMethod('show', {
accepts: [
{ arg: 'name', type: 'string' },
{ arg: 'lastName', type: 'string' }
],
returns: {arg: 'result', type: 'string'}
});
}
插入类似:
var yourVar = name;
pg.connect(dbUrl, function(err, client, done) {
client.query(
'INSERT into yourTable(name) VALUES ($1)',
['title'],
function(err, result) {
if (err) {
console.log(err);
} else {
console.log('row inserted');
}
});
});
取决于您的表和日志凭据
编辑:
要使用自动迁移,您必须首先:
在 /server/datasources.json 中创建数据源:
"mydb": {
"name": "mydb",
"connector": "postgresql"
}
连接到 /var/run/postgresql/.s.PGSQL.5432 中的 UNIX 域套接字:
{
"postgres": {
"host": "/var/run/postgresql/",
"port": "5432",
"database": "dbname",
"username": "dbuser",
"password": "dbpassword",
"name": "postgres",
"debug": true,
"connector": "postgresql"
}
}
在 /common/models/model.json 中定义你的模型,它应该是这样的:
var schema={
"name": "User",
"options": {
"idInjection": true,
"postgresql": {
"schema": "yourShema",
"table": "USER"
}
},
"properties": {
"id": {
"type": "Number",
"required": true,
"length": 64,
"precision": null,
"scale": null,
"postgresql": {
"columnName": "id",
"dataType": "integer",
"dataLength": 64,
"dataPrecision": null,
"dataScale": null,
"nullable": "NO"
}
},
"name": {
"type": "String",
"required": false,
"length": 40,
"precision": null,
"scale": null,
"postgresql": {
"columnName": "name",
"dataType": "character varying",
"dataLength": 40,
"dataPrecision": null,
"dataScale": null,
"nullable": "YES"
}
},
"lastName": {
"type": "String",
"required": false,
"length": 40,
"precision": null,
"scale": null,
"postgresql": {
"columnName": "lastName",
"dataType": "character varying",
"dataLength": 40,
"dataPrecision": null,
"dataScale": null,
"nullable": "YES"
}
}
}
那么您必须像这样在代码中调用Model.automigrate() 或Model.autoupdate():
ds.createModel(schema);
ds.autoupdate(schema) {
ds.discoverModelProperties('USER', function (err, props) {
console.log(props);
});
});
你肯定会改变一些事情,但我希望你能实现你想要的;)