I'd like to know if there is any intention to create a client for lucid in standalone mode, please.
I'm a dev at Rocketseat, an education company with 153,5k students and we use and teach AdonisJS to them. We also teach Express, but for that we use another ORM, but instead we would love to teach the Lucid ORM, since it is easy to implement and use.
Although it can be used in standalone mode, it leaves something behind once we can't work with migrations with one CLI. I tried using with adonis-cli but had no success.
Hello @HigoRibeiro
It will be quite some work to get Lucid along with the CLI commands to work in standalone mode. To be honest, I don't have enough bandwidth and brain power to work on that now. However, I am happy to collaborate, if you or someone wants to lead the feature.
Hi @HigoRibeiro, you mentioned you got Lucid working as standalone package? I would really like to understand what you did. I want to use it on multiple frameworks as well. I don't need the CLI. Anything you can share ? Thx!
Hi @Johnson444 !! It's simple to use that standalone!!
Follow these steps:
// config/database.js
export default {
connection: 'my-connection-name',
'my-connection-name': {
client: 'pg', // Driver of the connection
connection: {
// connections options, you can see that at knex
// http://knexjs.org/#Installation-client
},
},
};
// models/lucid.js
import lucid from '@adonisjs/lucid';
import databaseConfig from '../config/database';
export const { Model, Models } = lucid(databaseConfig);
// models/User.js
import { Model } from './lucid';
class User from Model { };
export default User;
// models/index.js
import { Models } from './lucid';
import UserModel from './User';
Models.add('User', UserModel); // This link the database connection with your model
export default User = Model.get('User'); // Expose your model linked with database connection
// Using express
// controllers/UserController.js
import { User } from '../models';
class UserController {
async index(request, response) {
const users = await User.all();
return response.json(users.toJSON());
}
}
traits as well;
Most helpful comment
Hi @Johnson444 !! It's simple to use that standalone!!
Follow these steps:
traitsas well;