javascript规范_javascript中流行的规范,以及为什么要关心

javascript规范

If you’re reading this, then chances are you have already heard the term ORM. For those of you who happened here by chance, an ORM is defined as ‘Object Relational Mapping’. Which in short, are an alternative method to traditional SQL queries for relational database management. Think of them as a translator from our preferred type of code to another.

如果您正在阅读本文,那么您可能已经听说过ORM这个词。 对于那些偶然发生在这里的人,ORM被定义为“对象关系映射”。 简而言之,这是用于关系数据库管理的传统SQL查询的替代方法。 将它们视为从我们喜欢的代码类型到另一种代码的翻译器。

This article will briefly break down the benefits of ORMs within the development process and how the most popular of these current ORM libraries can increase the efficiency of your JavaScript-based app.

本文将简要介绍ORM在开发过程中的好处,以及这些当前ORM库中最受欢迎的库如何提高基于JavaScript的应用程序的效率。

A basic SQL query might look something like this;

基本SQL查询可能看起来像这样。

SELECT * FROM Customers WHERE Last_Name='Thompson';

However, these queries typically increase in complexity rapidly and if not performed regularly the syntax can prove cumbersome. As developers, we are always looking for the “easiest” or most efficient way of doing things. The benefit of ORMs is that a developer can use their primary coding language to write these complex queries.

但是,这些查询通常会Swift增加复杂性,如果不定期执行,则语法可能会很麻烦。 作为开发人员,我们一直在寻找“最简单”或最有效的处理方式。 ORM的好处是开发人员可以使用其主要的编码语言来编写这些复杂的查询。

As a result, a fairly simple query like this;

结果是,这样的查询非常简单;

SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
FULL OUTER JOIN Orders
ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CustomerName

Can become as condensed as this single line query;

可以像此单行查询一样精简;

Person.joins(:country).where(countries: { gdp: 110 })
#"SELECT "people".* FROM "people"
#INNER JOIN "countires"
#ON "countries"."id" = "people"."country_id"
#WHERE "countries"."gdp" = 110"

This abstraction of SQL query complexity has many benefits for the efficiency of the production team and, as a result, ORM libraries have seen a rise in popularity over recent years.

SQL查询复杂性的这种抽象为生产团队的效率带来了许多好处,因此,近年来ORM库的流行度有所提高。

By this stage you are certainly convinced as to the necessity of ORMs and likely asking yourself “where can I get one of these life-changing libraries?”, and “which one should I choose?”. The next section will provide a breakdown of various highly regarded JS ORMs (in no particular order);

在此阶段,您肯定已经对ORM的必要性深信不疑,并且可能会问自己:“我可以从哪里获得这些改变生命的库中的一个?”,以及“我应该选择哪个?”。 下一节将提供各种备受推崇的JS ORM的细分(无特定顺序);

  1. TypeORM

    类型ORM

Logo for TypeORm
TypeORM logo
TypeORM徽标

TypeORM is an open-source tool that supports both Active Record and Data Mapper patterns. A key virtue of TypeORM and instrumental in its rapidly growing support base is its accessibility.

TypeORM是一个开源工具,同时支持Active Record和Data Mapper模式。 TypeORM的主要优点是可访问性,并且在其快速增长的支持基础中发挥了作用。

It currently supports a wide range of DB management systems including; MySQL, MariaDB, Postgres, CockroachDB, SQLite, Microsoft SQL Server, Oracle, SAP Hana, sql.js as well and MongoDB NoSQL database.

当前,它支持各种DB管理系统,包括: MySQL,MariaDB,Postgres,CockroachDB,SQLite,Microsoft SQL Server,Oracle,SAP Hana,sql.js以及MongoDB NoSQL数据库。

Furthermore, it is compatible with NodeJS, Browser, Ionic, Cordova, React Native, NativeScript, Expo, Electron platforms making it widely adopted across the development community.

此外,它与NodeJS,浏览器,Ionic,Cordova,React Native,NativeScript,Expo,Electron平台兼容,从而使其在整个开发社区中被广泛采用。

It is widely regarded as the first choice for many Typescript users and can be freely downloaded from GitHub.

它被广泛认为是许多Typescript用户的首选,可以从GitHub免费下载。

2. Prisma

2.棱镜

Image for post
Prisma Logo
棱镜徽标

Is another open-source database tool kit. It is an excellent option for those using TypeScript or Node.js and even has an auto-generated query builder.It currently supports PostgreSQL, SQLite, and MySQL.

是另一个开源数据库工具包。 对于使用TypeScript或Node.js的用户来说,它是一个极好的选择,甚至具有自动生成的查询生成器。它目前支持PostgreSQL,SQLite和MySQL。

Although this may exclude it as an option for some, Prisma has excellent documentation, great support channels, and an excellent VSCode plugin.

尽管对于某些人来说,这可能会排除它,但Prisma拥有出色的文档,强大的支持渠道以及出色的VSCode插件。

It is available to try or download from their site, or via GitHub.

可以尝试从其站点或通过GitHub下载。

3. Sequelize

3.续集

Image for post
Sequelize logo
续集徽标

Is a well known, promise-based ORM for Node.js. with a wide variety of features. It supports a wide variety of dialects including; PostgreSQL, MySQL, SQLite, MSSQL, and MariaDB.

是一个众所周知的基于诺言的Node.js ORM。 具有各种各样的功能。 它支持多种方言,包括; PostgreSQL,MySQL,SQLite,MSSQL和MariaDB。

It has decent, easily navigable documentation and a wealth of tutorials and guides. It is also a very stable ORM and highly regarded. Amongst its positives it allows for better management of exceptions or unexpected results, and also has middleware that allows for custom error messages for each field.

它具有体面,易于导航的文档以及大量的教程和指南。 它也是一个非常稳定的ORM,受到高度重视。 它的优点包括可以更好地管理异常或意外结果,还具有中间件,可以为每个字段提供自定义错误消息。

Available via GitHub.

可通过GitHub获得

4. Bookshelf

4.书架

Image for post
Bookshelf Logo
书架徽标

Is both a promise based JS ORM and also works with traditional callbacks interfaces. It is built on the Knex.js interface and compatible with PostgreSQL, MySQL, and SQLite3.

既是基于Promise的JS ORM,也可以与传统的回调接口一起使用。 它建立在Knex.js界面上,并与PostgreSQL,MySQL和SQLite3兼容。

Bookshelf separates itself from others by providing a simple library for common tasks when querying databases in JavaScript. Its concise, literate code base makes Bookshelf simple to read, understand, and extend.

书架通过在JavaScript中查询数据库时提供一个简单的库来执行常见任务,从而将自己与其他书架区分开来。 它简洁明了的代码库使书架易于阅读,理解和扩展。

It is available on GitHub and has a comprehensive test suite using Travis CI.

它在GitHub上可用,并具有使用Travis CI的全面测试套件。

5. Mongoose

5.猫鼬

Image for post
Mongoose Logo
猫鼬徽标

Mongoose is a NoSQL based Object Data Modelling (ODM) library for MongoDB and Node.js. It provides a straight-forward, schema-based solution to model your application data and provides a great deal of convenience when creating and managing data in MongoDB.

Mongoose是用于MongoDB和Node.js的基于NoSQL的对象数据建模(ODM)库。 它提供了一种基于模式的简单直接的解决方案来对应用程序数据进行建模,并在MongoDB中创建和管理数据时提供了极大的便利。

Mongoose supports both promises and callbacks and is designed to work in an asynchronous environment. It can be forked from GitHub.

Mongoose同时支持Promise和回调,并且旨在在异步环境中工作。 可以从GitHub分叉。

As you can see there is a wide variety of ORMs available for JavaScript developers to leverage in the endless pursuit of an optimized workflow. It is not the purpose of this article to provide a comprehensive review of all the options available but rather to highlight the benefits of making your CRUD operations using an ORM in your preferred language.

如您所见,JavaScript开发人员可以使用各种各样的ORM,以无休止地追求优化的工作流程。 本文的目的不是提供所有可用选项的全面概述,而是强调使用首选语言的ORM进行CRUD操作的好处。

After all, all these libraries can’t be wrong.

毕竟,所有这些库都不会出错。

If you would like to continue reading about the many benefits of ORMs there are are a few suggestions below.

如果您想继续阅读有关ORM的许多好处的信息,请参考以下建议。

ORM: Rethinking Data as objects by Jaya

ORM: Jaya重新将数据视为对象

What is ORM by Brian Cline

什么是Brian Cline的ORM

A Case for ORM, a Case against ORM by Mikhail Khorpyakov

一个针对ORM的案例,一个针对ORM的案例,作者Mikhail Khorpyakov

翻译自: https://medium.com/@jconheasman/popular-orms-in-javascript-and-why-you-should-care-63b35936b7b

javascript规范

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值