graphql redux_如何在Redux应用程序中使用GraphQL
graphql redux
by Howon Song
通过宋颂恩
如何在Redux应用程序中使用GraphQL (How to use GraphQL in your Redux app)
Fetching and managing data in Redux requires too much work. As Sashko Stubailo points out:
在Redux中获取和管理数据需要太多的工作。 正如Sashko Stubailo 指出的那样 :
Unfortunately the patterns for asynchronously loading server data in a Redux app aren’t as well established, and often involve using external helper libraries, like redux-saga. You need to write custom code to call your server endpoints, interpret the data, normalize it, and insert it into the store — all while keeping track of various error and loading states.
不幸的是,在Redux应用程序中异步加载服务器数据的模式还不够完善,通常涉及使用外部帮助程序库,例如redux-saga 。 您需要编写自定义代码来调用服务器端点,解释数据,对其进行规范化并将其插入存储中,同时还要跟踪各种错误和加载状态。
By the end of this tutorial, you will have learned how to solve this problem by letting the Apollo Client fetch and manage data for you. You will no longer have to write multiple action dispatchers, reducers, and normalizers to fetch and sync data between your front end and your back end.
在本教程结束时,您将学习如何通过让Apollo Client为您获取和管理数据来解决此问题。 您将不再需要编写多个动作分派器,Reducer和Normalizer来在前端和后端之间获取和同步数据。
But before starting the tutorial, make sure that:
但是在开始本教程之前,请确保:
You know the basics of GraphQL queries — if you’re entirely new to GraphQL, you should come back after doing this tutorial.
您知道GraphQL查询的基础知识—如果您是GraphQL的新手,那么应该在完成本教程后再回来。
You have some experience working with React/Redux — if not, you should come back after doing react tutorial and redux tutorial.
您有使用React / Redux的经验-如果没有,您应该在完成react教程和redux教程之后再回来。
In this tutorial, we will go through 6 sections together.
在本教程中,我们将一起经历6个部分。
- Setting up server environment (quick)设置服务器环境(快速)
- Setting up redux boilerplate app设置Redux样板程序
- Adding GraphQL client (Apollo Client)添加GraphQL客户端(Apollo客户端)
- Fetching data with GraphQL query使用GraphQL查询获取数据
- Fetching even more data获取更多数据
- Next steps下一步
1.设置服务器环境 (1. Setting up server environment)
First, we need a GraphQL server. The easiest way to have a running server is completing this awesome tutorial.
首先,我们需要一个GraphQL服务器。 使服务器运行的最简单方法是完成本很棒的教程 。
If you are feeling lazy, you can just clone my repo, which is almost the same server you’d get if you did the tutorial yourself. The server supports GraphQL queries to fetch data from a SQLite DB.
如果您感到懒惰,则可以克隆我的repo ,这与您亲自完成本教程时所获得的服务器几乎相同。 该服务器支持GraphQL查询以从SQLite数据库获取数据。
Let’s run it and see if it’s working correctly:
让我们运行它,看看它是否正常工作:
$ git clone https://github.com/woniesong92/apollo-starter-kit$ cd apollo-starter-kit$ npm install$ npm start
The server should be running at http://localhost:8080/graphql. Navigate to that page and see if you get a working GraphiQL interface with results like this:
服务器应在http:// localhost:8080 / graphql上运行 。 导航至该页面,查看是否有一个可用的GraphiQL界面,其结果如下:
GraphiQL lets you test different queries and immediately see what response you get from the server. If we don’t want an author’s last name and a fortune cookie message in a response, we can update the query like below:
GraphiQL使您可以测试不同的查询,并立即查看从服务器获得的响应。 如果我们不希望在回复中使用作者的姓氏和幸运饼干消息,则可以如下更新查询:
And that’s exactly how we like it. We confirmed that our server is running fine and returning good responses, so let’s start building the client.
这正是我们喜欢的方式。 我们确认我们的服务器运行良好并且返回了良好的响应,因此让我们开始构建客户端。
2.设置redux样板程序 (2. Setting up redux boilerplate app)
For simplicity, we will use a redux boilerplate so we can get all the setup (e.g. Babel, webpack, CSS, etc.) for free. I like this boilerplate because its setup is easy to follow and is client-side only — which makes it perfect for this tutorial.
为简单起见,我们将使用redux样板文件,以便我们免费获得所有设置(例如Babel,webpack,CSS等)。 我喜欢这个样板,因为它的设置很容易遵循,并且仅在客户端使用-这使其非常适合本教程。
$ git clone https://github.com/woniesong92/react-redux-starter-kit.git$ cd react-redux-starter-kit$ npm install$ npm start
Let’s navigate to http://localhost:3000/ to see if the client server is running.
让我们导航到http:// localhost:3000 /以查看客户端服务器是否正在运行。
Yay! The client is running. It’s time for us to start adding a GraphQL client. Again, our goal is to easily fetch data from the server and render it in the landing page (HomeView) without much effort by using GraphQL queries.
好极了! 客户端正在运行。 是时候开始添加GraphQL客户端了。 同样,我们的目标是通过使用GraphQL查询轻松地从服务器获取数据并将其呈现在登录页面(HomeView)中。
3.添加GraphQL客户端(Apollo客户端) (3. Adding GraphQL client (Apollo Client))
Install the packages apollo-client, react-apollo, and graphql-tag.
安装软件包apollo-client,react-apollo和graphql-tag。
$ npm install apollo-client react-apollo graphql-tag --save
Then, open the file src/containers/AppContainer.js, the root of our Redux app. This is where we pass down the redux store to child components, using the Provider from react-redux.
然后,打开文件src / containers / AppContainer.js,这是我们的Redux应用程序的根目录。 这是我们使用react-redux的Provider将redux存储传递给子组件的地方。
import React, { PropTypes } from 'react'import { Router } from 'react-router'import { Provider } from 'react-redux'
class AppContainer extends React.Component { static propTypes = { history: PropTypes.object.isRequired, routes: PropTypes.object.isRequired, routerKey: PropTypes.number, store: PropTypes.object.isRequired }
render () { const { history, routes, routerKey, store } = this.props
return ( <Provider store={store}> <div> <Router history={history} children={routes} key={routerKey} /> </div> </Provider> ) }}
export default AppContainer
We have to initialize an ApolloClient and replace the Provider from react-redux with ApolloProvider from react-apollo.
我们必须初始化ApolloClient并用react-apollo的ApolloProvider替换react-redux的Provider。
import React, { Component, PropTypes } from 'react'import { Router } from 'react-router'import ApolloClient, { createNetworkInterface, addTypename } from 'apollo-client'import { ApolloProvider } from 'react-apollo'
const client = new ApolloClient({ networkInterface: createNetworkInterface('http://localhost:8080/graphql'), queryTransformer: addTypename,})
class AppContainer extends Component { static propTypes = { history: PropTypes.object.isRequired, routes: PropTypes.object.isRequired, store: PropTypes.object.isRequired }
render () { const { history, routes } = this.props
return ( <ApolloProvider client={client}> <div> <Router history={history} children={routes} /> </div> </ApolloProvider> ) }}
export default AppContainer
That’s it! We just added a GraphQL client to a plain Redux app that easily.
而已! 我们只是将GraphQL客户端轻松添加到普通的Redux应用程序中。
Let’s go ahead and try our first GraphQL query.
让我们继续尝试第一个GraphQL查询。
4.使用GraphQL查询获取数据 (4. Fetching data with GraphQL queries)
Open src/views/HomeView.js
打开src / views / HomeView.js
import React from 'react'import { connect } from 'react-redux'import { bindActionCreators } from 'redux'
export class HomeView extends React.Component { constructor(props) { super(props) }
render () { return ( <div className='home'> <h1>Hello World</h1> </div> ) }}
// This is where you usually retrieve the data stored in the redux store (e.g posts: state.posts.data)const mapStateToProps = (state, { params }) => ({
})
// This is where you usually bind dispatch to actions that are used to request data from the backend. You will call the dispatcher in componentDidMount.const mapDispatchToProps = (dispatch) => { const actions = {}
return { actions: bindActionCreators(actions, dispatch) }}
export default connect( mapStateToProps, mapDispatchToProps)(HomeView)
HomeView is a conventional Redux container (smart component). To use GraphQL queries instead of action dispatchers to fetch data, we will make some changes together.
HomeView是常规的Redux容器(智能组件)。 要使用GraphQL查询而不是动作分配器来获取数据,我们将一起进行一些更改。
- Remove mapDispatchToProps() and mapStateToProps() completely.完全删除mapDispatchToProps()和mapStateToProps()。
import React from 'react'import { connect } from 'react-redux'import { bindActionCreators } from 'redux'
export class HomeView extends React.Component { constructor(props) { super(props) }
render () { return ( <div className='home'> <h1>Hello World</h1> </div> ) }}
export default connect({
})(HomeView)
2. Add mapQueriesToProps() and define a GraphQL query that will fetch the author information. Notice how this is the exactly the same query that we tested in the beginning using the GraphIQL interface on the server.
2.添加mapQueriesToProps()并定义一个GraphQL查询,以获取作者信息。 请注意,这与我们一开始使用服务器上的GraphIQL接口测试的查询完全相同。
import React from 'react'import { connect } from 'react-redux'import { bindActionCreators } from 'redux'
export class HomeView extends React.Component { constructor(props) { super(props) }
render () { return ( <div className='home'> <h1>Hello World</h1> </div> ) }}
// NOTE: This will be automatically fired when the component is rendered, sending this exact GraphQL query to the backend.const mapQueriesToProps = ({ ownProps, state }) => { return { data: { query: gql` query { author(firstName:"Edmond", lastName: "Jones"){ firstName posts { title } } } ` } }}
export default connect({
})(HomeView)
3. Replace connect from react-redux with connect from react-apollo and pass mapQueriesToProps as argument. Once mapQueriesToProps is connected to ApolloClient, the query will automatically fetch the data from the backend when HomeView is rendered, and pass the data down through props.
3.将react-redux的connect替换为react-apollo的connect,并将mapQueriesToProps作为参数传递。 将mapQueriesToProps连接到ApolloClient后,呈现HomeView时,查询将自动从后端获取数据,并将数据向下传递到props。
import React from 'react'import { connect } from 'react-apollo' // NOTE: different connect!import gql from 'graphql-tag' // NOTE: lets us define GraphQL queries in a template language
export class HomeView extends React.Component { constructor(props) { super(props) }
render () { return ( <div className='home'> <h1>Hello World</h1> </div> ) }}
const mapQueriesToProps = ({ ownProps, state }) => { return { data: { query: gql` query { author(firstName:"Edmond", lastName: "Jones"){ firstName posts { title } } } ` } }}
export default connect({ mapQueriesToProps})(HomeView)
4. Render the data that’s passed down from the props:
4.渲染从道具传下来的数据:
import React from 'react'import { connect } from 'react-apollo' // NOTE: different connect!import gql from 'graphql-tag' // NOTE: lets us define GraphQL queries in a template language
export class HomeView extends React.Component { constructor(props) { super(props) }
render () { const author = this.props.data.author if (!author) { return <h1>Loading</h1> }
return ( <div> <h1>{author.firstName}'s posts</h1> {author.posts && author.posts.map((post, idx) => ( <li key={idx}>{post.title}</li> ))} </div> ) }}
const mapQueriesToProps = ({ ownProps, state }) => { return { data: { query: gql` query { author(firstName:"Edmond", lastName: "Jones"){ firstName posts { title } } } ` } }}
export default connect({ mapQueriesToProps})(HomeView)
If all went well, your rendered HomeView should look like below:
如果一切顺利,则呈现的HomeView应该如下所示:
To fetch and render the data we wanted, we didn’t have to write any action dispatcher, reducer, or normalizer. All we had to do on the client was to write a single GraphQL query!
为了获取和呈现我们想要的数据,我们不必编写任何动作分派器,reducer或normalizer。 我们在客户端上要做的就是编写一个GraphQL查询!
We successfully achieved our initial goal. But that query was quite simple. What if we wanted to display all authors instead of just one author?
我们成功实现了最初的目标。 但是该查询非常简单。 如果我们想显示所有作者而不是一个作者怎么办?
5.获取更多数据 (5. Fetching even more data)
In order to fetch and display all authors, we have to update our GraphQL query and render method:
为了获取并显示所有作者,我们必须更新GraphQL查询和渲染方法:
import React from 'react'import { connect } from 'react-apollo' // NOTE: different connect!import gql from 'graphql-tag' // NOTE: lets us define GraphQL queries in a template language
export class HomeView extends React.Component { constructor(props) { super(props) }
render () { const authors = this.props.data.authors if (!authors) { return <h1>Loading</h1> }
return ( <div> {authors.map((author, idx) => ( <div key={'author-'+idx}> <h1>{author.firstName}'s posts</h1> {author.posts && author.posts.map((post, idx) => ( <li key={idx}>{post.title}</li> ))} </div> ))} </div> ) }}
const mapQueriesToProps = ({ ownProps, state }) => { return { data: { query: gql` query { authors { firstName posts { title } } } ` } }}
export default connect({ mapQueriesToProps})(HomeView)
However, once you refresh your browser HomeView page, you will notice that you have an error in your console:
但是,刷新浏览器的HomeView页面后,您会注意到控制台中出现错误:
ApolloError {graphQLErrors: Array[1], networkError: undefined, message: “GraphQL error: Cannot query field “authors” on type “Query”. Did you mean “author”?”}
ApolloError {graphQLErrors:Array [1],networkError:未定义,消息:“ GraphQL错误:无法查询类型为“ Query”的字段“ authors”。 您是说“作者”吗?”}
Ah, right! In our GraphQL server, we didn’t really define how to fetch authors.
啊,对! 在我们的GraphQL服务器中,我们并未真正定义如何获取作者 。
Let’s go back to our server and see what we have. Open the file apollo-starter-kit/data/resolvers.js
让我们回到服务器,看看有什么。 打开文件apollo-starter-kit / data / resolvers.js
import { Author, FortuneCookie } from './connectors';
const resolvers = { Query: { author(_, args) { return Author.find({ where: args }); }, getFortuneCookie() { return FortuneCookie.getOne() } }, Author: { posts(author) { return author.getPosts(); }, }, Post: { author(post) { return post.getAuthor(); }, },};
export default resolvers;
Looking at Query resolver, we notice that our GraphQL server only understands author and getFortuneCookie queries now. We should teach it how to “resolve” the query authors.
查看查询解析器时,我们注意到我们的GraphQL服务器现在仅了解author和getFortuneCookie查询。 我们应该教它如何“解决”查询作者。
import { Author, FortuneCookie } from './connectors';
const resolvers = { Query: { author(_, args) { return Author.find({ where: args }); }, getFortuneCookie() { return FortuneCookie.getOne() }, authors() { // the query "authors" means returning all authors! return Author.findAll({}) } }, ...};
export default resolvers;
We are not done yet. Open the file apollo-starter-kit/data/schema.js
我们还没有完成。 打开文件apollo-starter-kit / data / schema.js
const typeDefinitions = `...
type Query { author(firstName: String, lastName: String): Author getFortuneCookie: String}schema { query: Query}`;
export default [typeDefinitions];
This Schema makes it clear what kind of queries the server should expect. It doesn’t expect authors query yet so let’s update it.
该模式使服务器可以清楚地查询哪种查询。 它不希望作者查询,所以让我们对其进行更新。
const typeDefinitions = `...
type Query { author(firstName: String, lastName: String): Author getFortuneCookie: String, authors: [Author] // 'authors' query should return an array of // Author}schema { query: Query}`;
export default [typeDefinitions];
Now that our GraphQL server knows what the “authors” query means, let’s go back to our client. We already updated our query so we don’t have to touch anything.
现在,我们的GraphQL服务器知道“作者”查询的含义了,让我们回到客户端。 我们已经更新了查询,因此我们无需触摸任何内容。
export class HomeView extends React.Component {
...
const mapQueriesToProps = ({ ownProps, state }) => { return { data: { query: gql` query { authors { firstName posts { title } } } ` } }}
export default connect({ mapQueriesToProps})(HomeView)
With this query we expect to get all authors with their first names and posts. Go ahead and refresh the browser to see if we are getting the right data.
通过此查询,我们希望获得所有作者的名字和职位。 继续并刷新浏览器,看看我们是否获取了正确的数据。
If everything went well, your HomeView page will look like above.
如果一切顺利,您的HomeView页面将如上所示。
6.后续步骤 (6. Next steps)
This tutorial only explores a small part of GraphQL and leaves out a lot of concepts such as updating data on the server or using a different backend server (e.g. Rails).
本教程仅探讨GraphQL的一小部分,并省略了许多概念,例如更新服务器上的数据或使用其他后端服务器(例如Rails)。
While I work to introduce these in subsequent tutorials, you can read Sashko’s post or the Apollo Client Doc to better understand what’s going on under the hood (for example, what happened when we replaced Provider with ApolloProvider?).
当我在后续教程中介绍这些内容时,您可以阅读Sashko的帖子或Apollo Client Doc,以更好地了解幕后情况(例如,当我们用ApolloProvider替换Provider时发生了什么?)。
Digging into the source code of GitHunt, a full-stack Apollo Client and Server example app, also seems a great way to learn.
深入学习GitHunt的源代码(一个完整的Apollo客户端和服务器示例应用程序),也是一种学习的好方法。
If you have feedback, please leave it in the comment. I will try my best to be helpful :)
如果您有反馈,请留在评论中。 我会尽力为您提供帮助:)
翻译自: https://www.freecodecamp.org/news/tutorial-how-to-use-graphql-in-your-redux-app-9bf8ebbeb362/
graphql redux
相关文章:

原创:去繁存简,回归本源:微信小程序公开课信息分析《一》
以前我开过一些帖子,我们内部也做过一些讨论,我们从张小龙的碎屏图中 ,发现了重要讯息: 1:微信支付将成为重要场景; 2:这些应用与春节关系不小,很多应用在春节时,有重要的…

ubuntu 14.0 下github 配置
一:创建Repositories 1:首先在github下创建一个帐号。这个不用多说,然后创建一个Repositories。 2:然后在ubuntu下安装git相关的东东: 1sudo apt-get install git-core git-gui git-doc -y 3:在ubuntu本地创建一个ssh密匙: 1ssh-k…

OC 消息转发实现多继承
消息转发实现多继承 在OC 中,一个类只支持单继承,但是可以通过别的手段实现多继承。 利用消息转发实现多继承。 在OC 中,对象调用方法实际是在发消息,对象接收到一条消息的时候,消息函数随着对象的isa 指针到自己的…

chatscript_如何使用ChatScript构建您的第一个聊天机器人
chatscriptby Giorgio Robino通过乔治罗宾诺(Giorgio Robino) 如何使用ChatScript构建您的第一个聊天机器人 (How to build your first chatbot using ChatScript) 10–10–2018: article updated with new github repo url.2018年10月10日:文章更新为新的github r…

web安全浅析
就之前本人主持开发的金融产品所遇到的安全问题,设计部分请参见:http://www.cnblogs.com/shenliang123/p/3835072.html 这里就部分web安全防护就简单的交流: 1.1系统安全 1.1.1 客户端脚本安全 (1)跨站脚本攻击&#…

HDU 1556 Color the ball
题解:基础的树状数组区间修改,单点查询。 #include <cstdio> #include <cstring> int c[100005],a,b,n; int modify(int x,int num){while(x<n)c[x]num,xx&-x;} int query(int x){int s0;while(x>0)sc[x],x-x&-x;return s;} …

OC协议实现多继承
协议实现多继承 协议实现多继承的话,只是简答的提供了接口,并灭有提供实现的方式。 A #import <Foundation/Foundation.h>NS_ASSUME_NONNULL_BEGINprotocol StuAProtocal <NSObject>// 学生A 会游泳 - (void)swimming;endinterface Stude…

扶梯正确使用_乘坐自动扶梯解释CSS浮动
扶梯正确使用by Kevin Kononenko凯文科诺年科(Kevin Kononenko) 乘坐自动扶梯解释CSS浮动 (CSS Floats Explained By Riding An Escalator) 如果您曾经跳过自动扶梯,那么您可以快速了解浮动。 (If you have ever jumped on an escalator, then you can quickly und…

安卓学习-界面-ui-ListView
ListView继承自AbsListView AbsListView属性 XML属性代码说明 android:choiceMode setChoiceMode(int choiceMode) AbsListView.CHOICE_MODE_SINGLEAbsListView.CHOICE_MODE_MULTIPLEAbsListView.CHOICE_MODE_MULTIPLE_MODAL none :无选择模式 singleChoice:允许单…

swift 浮点型字符串的运算
// 1 两个浮点字符串之间的运算 let str1 "1.3"; let str2 "2.4"; let val1 Double(str1); let val2 Double(str2);let val3 CGFloat(Double(str1)!) * CGFloat(Double(str2)!);print(val3);// 2 string 转 double 不失精度 let formattor NumberFo…

为什么要在JavaScript中使用静态类型? (使用Flow进行静态打字的4部分入门)
by Preethi Kasireddy通过Preethi Kasireddy 为什么要在JavaScript中使用静态类型? (使用Flow进行静态打字的4部分入门) (Why use static types in JavaScript? (A 4-part primer on static typing with Flow)) As a JavaScript developer, you can code all day …

客户端如何连接 DataSnap Server 调用服务的方法
一般http访问的地址是 http://localhost:8099/datasnap/rest/TServerMethods1/EchoString/abc 一、用FDConnection1连接Datasnap服务器 FireDAC 连接Datasnap服务端。这个是tcp协议连接通讯,长连接。服务端不是没个方法都建立实例释放实例,而是连接的时…

Solr_全文检索引擎系统
Solr介绍: Solr 是Apache下的一个顶级开源项目,采用Java开发,它是基于Lucene的全文搜索服务。Solr可以独立运行在Jetty、Tomcat等这些Servlet容器中。 Solr的作用: solr是一个现成的全文检索引擎系统, 放入tomcat下可以…

swift 数组 filter reduce sort 等方法
数组的常用方法 swift 数组有很多的操作方法,但是用的时候用常常想不起来,就列出来看看 map 和 flatMap对数组中的元素进行变形操作filter主要对数组进行过滤reduce主要对数组进行计算sort对数组进行排序forEach循环遍历每一个元素min 和 max找出数组中…

im和音视频开发哪个更好_找时间成为更好的开发人员
im和音视频开发哪个更好There’s no time for anything. At least that’s how it feels doesn’t it? No time to learn all the things you think you need to learn to stay ahead of the curve. No time to go back and refactor that ugly piece of code. It works (sort…

4-8 同义词
雅思阅读:剑4~剑8阅读的所有同义词转换 雅思必考词汇 Cambridge 4 TEST 1 1. ignorepay no attentionnot pay any attentiontake no noticenot take any notice忽略,无视v. 2. encounterfaceconfrontmeet遇见,遭遇v. 3. mistaken viewmisconc…

swift可选类型
import UIKitvar array1 ["1","2","3","4","5"];// 1 if let 是一个组合关键字 来进行可选绑定 // 解决Optional对象解包时产生空对象的处理。 for i in array1 {print(i); }if let idx array1.firstIndex(of: "4&q…

java 配置及Eclipse安装
jdk下载 点我~ Java SE Development Kit 8u20 You must accept the Oracle Binary Code License Agreement for Java SE to download this software. Accept License Agreement Decline License Agreement Thank you for accepting the Oracle Binary Code License Agree…

golang 命令行_如何使用Golang编写快速有趣的命令行应用程序
golang 命令行by Peter Benjamin彼得本杰明(Peter Benjamin) 如何使用Golang编写快速有趣的命令行应用程序 (How to write fast, fun command-line applications with Golang) A while back, I wrote an article about “Writing Command-Line Applications in NodeJS”.不久前…

【Pyhon 3】: 170104:优品课堂: GUI -tkinter
from tkinter import * root Tk() root.title("BMS 图书管理系统") lbl Label(root, text书名:)#(1) lbl.pack() #(2) lbl.place(45.50) #(3) web 早期布局,, 常见。 lbl.grid(row0, column0) # web 早期布局,, 常见…

swift Sequence 和 SubSequence
1 序列 Sequence 序列协议是集合类型结构中的基础。 一个序列是代表有一系列具有相同类型的值,并且对这些值进行迭代。 协议中主要有两个参数,一个是元素Element,一个就是迭代器Iterator /// A type representing the sequences elements.…

PDF数据提取------1.介绍
1.关于PDF文件 PDF(Portable Document Format的简称,意为“便携式文件格式”)是由Adobe Systems在1993年用于文件交换所发展出的文件格式。它的优点在于跨平台、能保留文件原有格式(Layout)、开放标准,能自…

javascript_治愈JavaScript疲劳的研究计划
javascriptby Sacha Greif由Sacha Greif 治愈JavaScript疲劳的研究计划 (A Study Plan To Cure JavaScript Fatigue) Like everybody else, I recently came across Jose Aguinaga’s post “How it feels to learn JavaScript in 2016”.像其他所有人一样,我最近遇…

SQL Server中SELECT会真的阻塞SELECT吗?
在SQL Server中,我们知道一个SELECT语句执行过程中只会申请一些意向共享锁(IS) 与共享锁(S), 例如我使用SQL Profile跟踪会话86执行SELECT * FROM dbo.TEST WHERE OBJECT_ID 1 这个查询语句,其申请、释放的锁资源的过程如下所示: 而且从最常见…

appium IOS真机测试
看了 http://blog.csdn.net/today520/article/details/36378805 的文章,终于在真机上面测试成功。 由于没有开发者账号,不能发布应用到机器上面。所以就用了网易新闻的客户端来测试 没有开发者账号,貌似不能真正的开始测试。只能启动一下客户…

siwft 写时复制 Copy-On-Write
写时复制 Copy-On-Write 1 定义 在siwft 标准库中,Array,Dictionary,Set这样的集合类型是通过写时复制来实现的。 import Foundationvar a1 [1,2,3]; var a2 a1;// 将a1 复制给 a2,地址打印结果是相同的// 0x1--0x2--0x3 pri…

超越技术分析_超越技术面试
超越技术分析by Jaime J. Rios由Jaime J. Rios 超越技术面试 (Transcending the Technical Interview) “Wow. What a chastening and shameful experience that was.”“哇。 那真是一种令人st目结舌的经历。” This was my immediate mental reaction after I completed my…

轻松获取LAMP,LNMP环境编译参数配置
轻松获取LAMP,LNMP环境编译参数配置 作者:Mr.Xiong /分类:系统管理 字号:L M S大家是否遇到过去了新公司,公司内的LAMP,LNMP等所有的环境都是配置好的(已经在提供服务了),公司又没有留下部署文档…

java内存分配--引用
栈内存 对象地址 堆内存 存放属性 public class TestDemo{ public static void main(String args[]){ Person perA new Person(); //出现new百分之百就是要申请堆内存 perA.name"王强"; //perA 地址存放在栈内存中,同一块内存只能存…

iOS NSObject对象内存大小
NSObject内存大小 类的本质是结构体 无须赘述 struct NSObject { Class isa; };一个类对象的实例大小是8个字节 之所以打印出的16个字节,是因为一个NSObject 最小开辟16个字节 NSObject *obj [[NSObject alloc]init];// class_getInstanceSize 这是runtime 获…