AdonisJS Tutorial - Query Builder and Lucid ORM [ Build a Simple API - Part 6 ] (2018)

preview_player
Показать описание
In this video we'll go over Lucid, Query Builder and models.

Adonis uses Knex under the hood to power the Query Builder.

Lucid is the Adonis implementation of the Active Record pattern. It wraps the Query Builder to make it easy and enjoyable to interact with the database and define relationships between our mysql tables.

Together we'll go over some simple ways to use Lucid and compare it to using the Query Builder directly.

Рекомендации по теме
Комментарии
Автор

Hello Patrick,
Thank you so much for your time and effort delivering this material. I found it informative and easy to follow.
I have a note - this video in 1:53 shows the CustomerController already has its method implemented with details.
I guess you have it yourself. However, there is no video for going through that and explaining it.
Keep up the great work!
Best,
Faisal

Mhtwy
Автор

Some important things missing from the video:

1) When sending post requests, make sure your headers are set properly. In Postman in particular, you'll need to set these manually.

step 1: In Postman select the Headers tab just below where you post the request URL.
step 2: Add the following headers: Content-Type -> application/json and X-Requested-With -> XMLHttpRequest.

Setting these will ensure that the application doesn't reject the data being sent up to create the new record.

2) creating routes.

in the start/routes.js file you need to setup your routes like so:

ie for Customer routes:

// Customers
Route.get('customers', 'CustomerController.index')
Route.get('customers/:id', 'CustomerController.show')
Route.post('customers', 'CustomerController.store')
Route.patch('customers/:id', 'CustomerController.update')
Route.delete('customers/:id', 'CustomerController.delete')

When I post another video going over routes, I'll link to it here.

buildtolearn
Автор

At 9:28, you say, "We're just accessing `.create()` on the customer model directly" and then proceed to explain how this method returns the instance of the Customer model. You seem to imply that the instance is not wrapped like it was in the example using `.save()`. Does this mean if I wanted to send customer to the view after using `create()`, I would not need to use `.toJson()`?

xmatthewday
Автор

Great tutorial, I have a problem when run with OracleDB. The request returns the follow message:

"Error
insert into "customers" ("created_at", "description", "name", "updated_at") values (:1, :2, :3, :4) returning "id" into :5 - ORA-01843: not a valid month"

Do you know how fix that ?

Thank you.

pcgs_
Автор

i followed your tutorial but the values for the customer is not storing to the database, the id, timestamps, get stored, but the name and description are not being stored.

oluwabukolatina
Автор

Hi, where in this tutorial are the routes created? Also, in the Controller I don't see the model being imported. Did I miss that as well?

rogermarsh
Автор

Question: as you have already defined the method "show" and you're already validating if there's a customer or not, would it be a bad practice to call "show" inside the "update" method?

degenroxx
Автор

Having issues understanding the docs regarding doing bulk updates. Seems trivial, but I've been stuck for a bit.


I have a form, where one user can have multiple pickups. The data is coming in like below.
const pickups = [ {id:1, city:downey, }, {id:2, city:paramount} ]

const newPickups = await Pickup.update(pickups) //this is wrong I have no clue though.

BornGamble
Автор

Maybe on delete it could return a true boolean and not the id because the model doesn't exist anymore when the request succeeded

FranckMercado
Автор

How you use the debugger of vscode like that?

vitor
Автор

I'm having difficulty returning at least one value from my db. I followed the documentation on Adonis and I'm not having any luck.

jmartecep
Автор

I got lost too, the video is missing Routes and Models ... better take a look at github code...

tecnoPTY
Автор

I disagree with what you said about "validation should be done on the frontend" because frontend validation can be easily bypassed by anyone that knows what they're doing. Backend validation is a safer way to really make sure that your data is consistent.

isidrogonzalez
Автор

i was following up the tuto, , , then now I'm lost...

mreddygi
Автор

Hi Patrick.. Thank you so much for your work. It is really helpful. But as a personal opinion, it will also be very helpful if you can also address setting up the Postman for making POST calls like you are doing in the video. Although I followed the steps that you have added as a part of missing information but it's still not working for me. While making the POST request, I am getting 500Internal Server Error. This is what I did:

shivangchaturvedi
join shbcf.ru