我如何在 adonisJS 中翻译从 php 编写的这段代码?
How can i translate this code written from php in adonisJS?
我在PHP中有一堆代码,我想把它翻译成AdonisJS。
我这里有一个来自数据库的 table,我想使用此代码迁移到 Adonis。
这是PHP中的默认代码:
$schema = new \Doctrine\DBAL\Schema\Schema();
$myTable = $schema->createTable("user_comenzi");
$myTable->addColumn("id", "integer", array("unsigned" => true,"autoincrement"=>true));
$myTable->addColumn("user_id", "integer", array("unsigned" => true));
$myTable->addColumn("adresa_id", "integer", array("unsigned" => true));
$myTable->addColumn("creat", "datetime", array());
$myTable->addColumn("status", "integer", array("default"=>0));
$myTable->addColumn("comanda", "text");
$myTable->setPrimaryKey(array("id"));
//$schema->createSequence("comenzi_seq");
$platform = new \Doctrine\DBAL\Platforms\SqlitePlatform();
$queries = $schema->toSql($platform); // get queries to create this schema.
print_r($queries);
$app['db']->query($queries[0]);
在 AdonisJS 中应该是这样的:
class UserComenziSchema extends Schema {
up () {
this.create('user_comenzi', (table) => {
table.increments()
table.integer('user_id').unsigned()
table.integer('adresa_id').unsigned()
table.time('creat')
table.integer('status').defaultTo(0)
table.text('comanda')
table.timestamps()
})
}
down () {
this.drop('user_comenzi')
}
}
我只想看看我的代码是否错误,如果我错了,为什么?
将 table.time('creat')
更改为 table.datetime('creat')
就可以了
我在PHP中有一堆代码,我想把它翻译成AdonisJS。
我这里有一个来自数据库的 table,我想使用此代码迁移到 Adonis。
这是PHP中的默认代码:
$schema = new \Doctrine\DBAL\Schema\Schema();
$myTable = $schema->createTable("user_comenzi");
$myTable->addColumn("id", "integer", array("unsigned" => true,"autoincrement"=>true));
$myTable->addColumn("user_id", "integer", array("unsigned" => true));
$myTable->addColumn("adresa_id", "integer", array("unsigned" => true));
$myTable->addColumn("creat", "datetime", array());
$myTable->addColumn("status", "integer", array("default"=>0));
$myTable->addColumn("comanda", "text");
$myTable->setPrimaryKey(array("id"));
//$schema->createSequence("comenzi_seq");
$platform = new \Doctrine\DBAL\Platforms\SqlitePlatform();
$queries = $schema->toSql($platform); // get queries to create this schema.
print_r($queries);
$app['db']->query($queries[0]);
在 AdonisJS 中应该是这样的:
class UserComenziSchema extends Schema {
up () {
this.create('user_comenzi', (table) => {
table.increments()
table.integer('user_id').unsigned()
table.integer('adresa_id').unsigned()
table.time('creat')
table.integer('status').defaultTo(0)
table.text('comanda')
table.timestamps()
})
}
down () {
this.drop('user_comenzi')
}
}
我只想看看我的代码是否错误,如果我错了,为什么?
将 table.time('creat')
更改为 table.datetime('creat')
就可以了