نکات کاربردی



میخواهیم نوع ستون second را از string به float برای تمام داکیومنت ها (رکوردها) تغییر دهیم مراحل زیر را طی میکنیم:

1-

PUT  _ingest/pipeline/convert-call-seconds-to-float
{
  "description": "converts the content of the second field to an float",
  "processors" : [
    {
      "convert" : {
        "field" : "second",
        "type": "float",
        "ignore_missing": true
      }
    }
  ]
}

2-

POST /db_name/_update_by_query?pipeline=convert-call-seconds-to-float

مرجع:

Update By Query API


Case Styles: Camel, Pascal, Snake, and Kebab Case

TLDR;
  • camelCase
  • PascalCase
  • snake_case
  • kebab-case

Removing spaces between words

In programming, we often remove the spaces between words because programs of different sorts reserve the space (‘ ’) character for special purposes. Because the space character is reserved, we cannot use it to represent a concept that we express in our human language with multiple words. As an example, the concept of user login count” is not referenced in our code as user login count” often. We do not do the following:

user login count = 5;

A typical language parse would treat each word as a separate concept. User,” login,” and count” would each be treated as separate things. So, we do something like the following:

userLoginCount = 5;

Now, the parser will see one concept — userLoginCount” — and us programmers can easily see the representation.

The best way to combine words

There is no best way to combine words. In the above example, we removed spaces and capitalized the each word following the first word. There are, however, a great number of algorithms for combining words, and a few very common ones.

The commonly used strategies for combining words are: camel case, pascal case, snake case, and kebab case. We’ll go over those here.

Camel Case (camelCase)

three camels standing on street” by

Lombe Kabaso on 

Unsplash

Camel case combines words by capitalizing all words following the first word and removing the space, as follows:

Raw: user login count”
Camel Case: userLoginCount”

This is a very popular way to combine words to form a single concept and is often used as a convention in variable declaration in many languages.

Pascal Case (PascalCase)

Pascal case combines words by capitalizing all words (even the first word) and removing the space, as follows:

Raw: user login count”
Pascal Case: UserLoginCount”

This is also very popular way to combine words to form a single concept and is often used as a convention in declaring classes in many languages.

Snake Case (snake_case)

brown snake” by

David Clode on 

Unsplash

Snake case combines words by replacing each space with an underscore (‘_’) and, in the all caps” version, all letters are capitalized, as follows:

Raw: user login count”
Snake Case: user_login_count”
Snake Case (All Caps): ”USER_LOGIN_COUNT”

This style when capitalized often used as a convention in declaring constants on in many languages. When lower cased, it used conventionally in declaring database field names.

Kebab Case (kebab-case)

barbecue on brown board” by

pan xiaozhen on 

Unsplash

Kebab case combines words by replacing each space with a dash (‘-’), as follows:

Raw: user login count”
Kebab Case: user-login-count”

This style is often used in URLs, for example, www.blog.com/cool-article-1”. It is a nice, clean, human readable way to combine the words.

Which is best?

There is no best method of combining words. The main thing is to be consistent with the convention used, and, if you’re in a team, to come to an agreement on the convention together.

thanksForReading!

ThanksForReading!

THANKS_FOR_READING_!

thanks-for-reading-!

Cheers!


دو کد زیر را درنظر بگیرید:

حالت الف : بدون استفاده ازuses

@Mapper(componentModel = "spring")
public interface SchoolMapper extends EntityMapper<SchoolDTO, SchoolEntity> {
@Mapping(source = "personId", target = "person.id") School toEntity(SchoolDTO schoolDTO);
}

حالت ب: با استفاده ازuses

@Mapper(componentModel = "spring", uses = { PersonMapper.class }) 
 public interface SchoolMapper extends EntityMapper<SchoolDTO,SchoolEntity>{ 

  @Mapping(source = "personId", target = "person") 
  School toEntity(SchoolDTO schoolDTO); 
 } 

حالت ب باعث میشود کد تمیزتر و خواناتری تولید شود


  • ساده ترین راه برای نمایش کوئری ها در کنسول(standard out) این است که خط زیر را در فایل application.properties اضافه شود:

spring.jpa.show-sql=true

  • برای زیباسازی و یا چاپ زیبا SQL، می توان خط زیر را اضافه کرد:

spring.jpa.properties.hibernate.format_sql=true
  • برای نمایش مقادیر ، میتوان خط زیر اضافه کرد:
logging.level.org.hibernate.type=TRACE

  • می توان خطوط فوق را با فرمت YAML بشکل زیر در فایل application.properties افزود:

spring:
  jpa:
    properties:
      hibernate:
        show_sql: true
        format_sql: true
logging:
  level:
    org:
      hibernate:
        type: trace


File templates

  • خصوصیاتی از محتویات پیش فرضی هستند که هنگام ایجاد یک فایل جدید تولید می شود.
  • بسته به نوع فایل شما ایجاد می شود، قالب ها کد اولیه و قالب بندی را ارائه می دهد که انتظار می رود در تمام فایل های این نوع باشد.


File and Code Templates

@‏author



Cookies و local storage خدمات متفاوتی را ارایه میکنند.

Cookies : عمدتا برای خواندن server-side هستند.

local storage : فقط توسط client-side قابل خواندن است.

  • اگر اطلاعات در سمت کلاینت مورد نیاز باشد، استفاده از کوکی موجب هدر رفتن پهنای باند می شود.
  • اگر اطلاعات در سمت سرور مورد نیاز باشد، استفاده از local storage مفید نیست.

Web Storages بهتر از Cookies

local-storage-vs-cookies


  • Querydsl

یک چارچوب است که امکان ساخت پرس وجوی های مشابه با دستور SQL را مهیا می کند.

به جای نوشتن درخواست ها به صورت رشته های inline یا انتقال آنها به فایل های XML، آنها می توانند از طریق یک API ساده و روان مانند Querydsl ساخته شوند.


  • برای مثال مزایای استفاده از API روان در مقایسه با رشته های ساده
  1. تکمیل کد در IDE
  2. انواع و خواص دامنه را می توان بصورت ایمن ارجاع داد.
  3. اصلاح تغییرات در انواع دامنه بهتر انجام می شود.

  • Querydsl برای نگهداری مطمین پرس و جوهای HQL متولد شد.
  • ساختار افزایشی پرس و جوهای HQL نیازمند پیوند رشته است و نتیجه را در خواندن کد سخت می کند. منابع نامناسب برای انواع و خواص دامنه از طریق رشته های ساده، مسئله دیگری با ساختار HQL مبتنی بر String بود.
  • با تغییر دامنه مدل ایمنی نوع مزایای زیادی را در توسعه نرم افزار به ارمغان می آورد. تغییرات دامنه به طور مستقیم در نمایش داده ها منعکس شده است و تکمیل خودکار در ساخت پرس و جو باعث ایجاد سریعتر و ایمن تر ساخت پرس و جو می شود.

Querydsl Reference Guide


‎@OneToMany:

برای تعیین ارتباط یک به چند استفاده می شود:

عناصر اختیاری:

-

cascade

-

fetch

-

mappedBy

-

orphanRemoval

-

targetEntity

اگر برای مشخص کردن نوع عنصر مجموعه از generics استفاده شود، نوع موجودیت هدف مرتبط مشخص نمی شود.



The best way to map a @OneToMany relationship with JPA and Hibernate


Resource :
هر جزء فیزیکی یا مجازی با دسترسی محدود در سیستم کامپیوتری است


URI :Uniform Resource Identifier

تعاریف URI

- توالی پیوسته ای از کارکترهاست برای شناسایی یه منبع(Resource ) فیزیکی یا انتزاعی.

- رشته ای است که به یک منبع اشاره دارد.


فرمت URI

      URI         = scheme ":" hier-part [ "?" query ] [ "#" fragment ]

      hier-part   = "//" authority path-abempty
                  / path-absolute
                  / path-rootless
                  / path-empty



7 Rules for REST API URI Design


آخرین ارسال ها

آخرین جستجو ها