I’m struggling when creating collections from my nodejs code, they are created in the database, but do no appear within the main data source. Following the example here https://docs.nocobase.com/api/database is more than enough to get the table created, since it’s based off of sequelize I followed the normal pattern I use for sequelize.
I connected pgAdmin to the internal database so I could verify. The table is created upon initial run, the data is written into the table. The table just won’t display in the main data source. I can use the http api to do this, but this is far easier to do systematically.
import { Database } from ‘@nocobase/database’
// PostgreSQL database configuration parameters
export default const database = new Database({
dialect: ‘postgres’,
database: ‘database’,
username: ‘username’,
password: ‘password’,
host: ‘localhost’,
port: ‘port’
})
Model file:
import { database } from ‘database connection example above’
const UserCollection = database.collection({
name: ‘users’,
fields: [
{
name: ‘name’,
type: ‘string’,
},
{
name: ‘age’,
type: ‘integer’,
},
],
});
await UserCollection.sync() I’ve also used database.sync() here
export default UserCollection
Example in use
import { UserCollection } from ‘example above’
const UserRepository = UserCollection.repository();
await UserRepository.create({
name: ‘Mark’,
age: 18,
});
const create = await UserCollection.create({