Avi*_*jit 6 database android parse-platform
我想使用解析数据库来开发Web应用程序,因为数据将从桌面PC上传,并且将在解析移动应用程序中进行相同的撤销.
是否可以将解析数据库用于网站后端?
因为我想为应用程序和桌面版本使用相同的解析数据库.
任何人都可以帮助我,通过提供一些想法如何实现这一点?
提前致谢.
Dha*_*mar 15
Is it possible to use the parse database for website backend ?
Run Code Online (Sandbox Code Playgroud)
Since I want to use same parse database for application and desktop version.
Run Code Online (Sandbox Code Playgroud)
是的,您可以将相同的数据库用于应用程序和桌面版本.
使用ANDROID创建对象的商店数据,如:
ParseObject gameScore = new ParseObject("GameScore");
gameScore.put("score", 1337);
gameScore.put("playerName", "Sean Plott");
gameScore.put("cheatMode", false);
gameScore.saveInBackground();
Run Code Online (Sandbox Code Playgroud)
上面的代码是parse.com中的create table(使用object存储数据时会自动创建数据库.)检查仪表板:如下图所示
获取数据尝试这种方式:
ParseQuery query = new ParseQuery("GameScore");
query.getInBackground("xWMyZ4YEGZ", new GetCallback() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
// object will be your game score
} else {
// something went wrong
}
}
});
Run Code Online (Sandbox Code Playgroud)
同样可以用于WEB应用程序以及桌面应用程序(REST API)
对于创建表用户我必须创建如下对象:
ParseObject gameScore = new ParseObject("User");
gameScore.put("First Name", "dhaval");
gameScore.put("Last Name", "Sodha");
gameScore.put("Email", "xyz@gmail.com");
gameScore.put("Phone", "9876543210");
gameScore.put("Address", "xyz");
gameScore.put("City", "ahmedabad");
gameScore.put("Country", "India");
gameScore.saveInBackground();
Run Code Online (Sandbox Code Playgroud)
上面的对象ll创建包含字段的表(ID,名字,姓氏,电子邮件,电话,地址,城市,...时间,创建...等)
编辑:
得到像(SELECT * FROM USER WHERE CITY = 'AHMEDABAD' and COUNTRY = 'INDIA'
)的数据
ParseQuery lotsOfWins = new ParseQuery("User");
lotsOfWins.whereEqualTo("city", "Ahmedabad");
ParseQuery fewWins = new ParseQuery("User");
fewWins.whereEqualTo("country", "India");
List<ParseQuery> queries = new ArrayList<ParseQuery>();
queries.add(lotsOfWins);
queries.add(fewWins);
ParseQuery mainQuery = ParseQuery.or(queries);
mainQuery.findInBackground(new FindCallback() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
Log.d("score", "Retrieved " + scoreList.size() + " scores");
// HERE SIZE is 0 then 'No Data Found!'
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
这里:public void done(List<ParseObject> scoreList, ParseException e)
你得到对象的结果
List<ParseObject>
:是按查询返回的对象列表.
ParseException
:如果发生异常是..
因此,scoreList.size()
给出按查询返回的所有对象的总大小.
如何获取数据:
String username = scoreList.getString("username");
Run Code Online (Sandbox Code Playgroud)
如何保存文件:(无论是什么MIME类型,如png,jpg,doc,txt ....等)它适用于所有人
使用以下代码上传文件:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
USERIMAGE.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
String UsetPhoto = "user"+System.currentTimeMillis()+"image";
ParseFile file = new ParseFile(UsetPhoto, byteArray);
ParseObject gameScore = new ParseObject("UserDetails");
gameScore.put("userName", "" + userName.getText().toString());
gameScore.put("userPhoto", "" + file);
gameScore.saveInBackground();
Run Code Online (Sandbox Code Playgroud)
使用上述对象从parse API中检索文件:
ParseFile applicantResume = (ParseFile)gameScore.get("userPhoto");
applicantResume.getDataInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null) {
// data has the bytes for the resume
} else {
// something went wrong
}
}
});
Run Code Online (Sandbox Code Playgroud)
在这里你得到: public void done(byte[] data, ParseException e)
byte[]
:byte[]
of file(无论文件类型是什么 - 如果你已经上传了png,那么将该字节保存为png).
ParseException
:如果发生异常是..
归档时间: |
|
查看次数: |
5015 次 |
最近记录: |