在我的PostgreSQLModel
steam类中,我使用简单的Migration
扩展来创建数据库表。
extension Order: Migration {
static func prepare(on connection: PostgreSQLConnection) -> Future<Void> {
return Database.create(self, on: connection) { builder in
try addProperties(to: builder)
try builder.addReference(from: \.stationID, to: \Station.id)
}
}
}
我遇到的问题是我的Date
字段被创建为timestamp without time zone
而我真正想要的只是date
。我该如何指定?我是否必须跳过addProperties
并自行为每个列在构建器上手动调用addField
?
答案 0 :(得分:2)
不确定这是否是最好的方式,但我最终做到了这一点:
try {
String str;
Scanner sc=new Scanner(System.in);
File fw = new File("C:/Users/MYPC/Desktop/abcd.txt");
FileOutputStream fos = new FileOutputStream(fw);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
do {
System.out.println("Enter your lines");
str=sc.nextLine();
if(!str.equals("stop")) {
bw.write(str);
bw.newLine();
} else {
bw.close();
}
} while(!str.equals("stop"));
} catch (Exception ex) {
System.out.println(ex);
}