exists

NodeJS笔记: 文件操作大全

断了今生、忘了曾经 提交于 2019-12-18 18:27:03
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 文件I/O fs模块的基本用法 开发中我们经常会有文件I/O的需求,node.js中提供一个名为fs的模块来支持I/O操作,fs模块的文件I/O是对标准POSIX函数的简单封装。 writeFile函数的基本用法 文件I/O,写入是必修课之一。fs模块提供writeFile函数,可以异步的将数据写入一个文件, 如果文件已经存在则会被替换。用法如下: 例: fs.writeFile(filename, data, callback) var fs= require("fs"); fs.writeFile('test.txt', 'Hello Node', function (err) { if (err) throw err; console.log('Saved successfully'); //文件被保存 }); appendFile函数的基本用法 writeFile函数虽然可以写入文件,但是如果文件已经存在,我们只是想添加一部分内容,它就不能满足我们的需求了,很幸运,fs模块中还有appendFile函数,它可以将新的内容追加到已有的文件中,如果文件不存在,则会创建一个新的文件。使用方法如下: 例: fs.appendFile(文件名,数据,编码,回调函数(err)); var fs= require(

sqlalchemy exists for query

孤者浪人 提交于 2019-12-18 10:37:27
问题 How do I check whether data in a query exists? For example: users_query = User.query.filter_by(email='x@x.com') How I can check whether users with that email exist? I can check this with users_query.count() but how to check it with exists ? 回答1: The following solution is a bit simpler: from sqlalchemy.sql import exists print session.query(exists().where(User.email == '...')).scalar() 回答2: The most acceptable and readable option for me is session.query(<Exists instance>).scalar() like session

Hive-HiveDDL(Database+Table+Partition)

烂漫一生 提交于 2019-12-18 10:05:01
1. Hive DDL之数据库 官网: https://cwiki.apache.org/confluence/display/Hive/GettingStarted#GettingStarted-DDLOperations 1.1 创建数据库 创建数据库语法(方括号表示可选项): CREATE (DATABASE|SCHEMA) [IF NOT EXISTS] database_name [COMMENT database_comment] [LOCATION hdfs_path] [WITH DBPROPERTIES (property_name=property_value, ...)]; 实验 hive (default)> CREATE DATABASE IF NOT EXISTS ruozedata_hive; # 创建数据库 OK Time taken: 2.689 seconds hive (default)> exit; [ruoze@rzdata001 ~]$ [ruoze@rzdata001 ~]$ hadoop fs -ls /user/hive/warehouse 19/12/15 13:38:34 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your

zookeeper 介绍

我只是一个虾纸丫 提交于 2019-12-18 03:52:02
ZooKeeper 是一个分布式的,开放源码的分布式应用程序协调服务,它包含一个简单的原语集,分布式应用程序可以基于它实现同步服务,配置维护和命名服务等。 Zookeeper是hadoop的一个子项目,其发展历程无需赘述。在分布式应用中,由于工程师不能很好地使用锁机制,以及基于消息的协调机制不适合在 某些应用中使用,因此需要有一种可靠的、可扩展的、分布式的、可配置的协调机制来统一系统的状态。Zookeeper的目的就在于此。本文简单分析 zookeeper的工作原理,对于如何使用zookeeper不是本文讨论的重点。 1 Zookeeper的基本概念 1.1 角色 Zookeeper中的角色主要有以下三类,如下表所示: 系统模型如图所示: 1.2 设计目的 1.最终一致性:client不论连接到哪个Server,展示给它都是同一个视图,这是zookeeper最重要的性能。 2 .可靠性:具有简单、健壮、良好的性能,如果消息m被到一台服务器接受,那么它将被所有的服务器接受。 3 .实时性:Zookeeper保证客户端将在一个时间间隔范围内获得服务器的更新信息,或者服务器失效的信息。但由于网络延时等原因,Zookeeper不能保证两个客户端能同时得到刚更新的数据,如果需要最新数据,应该在读数据之前调用sync()接口。 4 .等待无关(wait-free)

Mysql How to only select from a column if the column exists

孤者浪人 提交于 2019-12-18 03:44:57
问题 I need to be able to check if a column exists and if it does then I want to SELECT from it. I am trying lots of different variations but I'm not even sure if this is possible. Here's my latest attempt: SELECT IF (EXISTS (SELECT `Period` AS `Period` FROM myview), `PERIOD`, IF (EXISTS (SELECT `Country` AS `COUNTRY` FROM myview),`COUNTRY` FROM myview ; Any ideas? EDIT I had seen the other question on here: MySQL, Check if a column exists in a table with SQL But I still struggle with the if

How to check if a file exists in javascript?

China☆狼群 提交于 2019-12-17 20:26:53
问题 I'm using the jquery library to load the content of an html file. Something like this: $("#Main").load("login.html") If the file (in this case 'login.html') does not exist, I would like to detect it so that I can redirect the user to an error page for example. Any ideas how I can detect if the file to load exists or not? 回答1: You can use the ajaxComplete event, whis gives you access to the xhr object which you can query the status of the request e.g a status of 404 will mean the file does not

mysql insert if value not exist in another table

≡放荡痞女 提交于 2019-12-17 20:01:54
问题 I have two tables that store value as VARCHAR . I'm populating table and I want just insert values in one of tables if they are not exist in other table. Something like: INSERT IF IS EMPTY(SELECT * FROM t1 where v='test') INTO t2 (v) VALUES ('test') How Can I do that? 回答1: You need to use some type of INSERT...SELECT query. Update (after clarification): For example, here is how to insert a row in t2 if a corresponding row do not already exist in t1 : INSERT INTO t2 (v) SELECT temp.candidate

How to check if a directory/file/symlink exists with one command in Ruby

微笑、不失礼 提交于 2019-12-17 10:46:58
问题 Is there a single way of detecting if a directory/file/symlink/etc. entity (more generalized) exists? I need a single function because I need to check an array of paths that could be directories, files or symlinks. I know File.exists?"file_path" works for directories and files but not for symlinks (which is File.symlink?"symlink_path" ). 回答1: The standard File module has the usual file tests available: RUBY_VERSION # => "1.9.2" bashrc = ENV['HOME'] + '/.bashrc' File.exist?(bashrc) # => true

SQL 判断 ‘表,存储过程,函数 ...’ 已是否存在

点点圈 提交于 2019-12-17 06:06:30
下面为您介绍sql下用了判断各种资源是否存在的代码,需要的朋友可以参考下,希望对您学习sql的函数及数据库能够有所帮助。 库是否存在 if exists(select * from master..sysdatabases where name=N'库名') print 'exists' else print 'not exists' --------------- -- 判断要创建的表名是否存在 if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) -- 删除表 drop table [dbo].[表名] GO --------------- --判断要创建临时表是否存在 If Object_Id('Tempdb.dbo.#Test') Is Not Null Begin print '存在' End Else Begin print '不存在' End --------------- -- 判断要创建的存储过程名是否存在 if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[存储过程名]') and

Checking if a directory exists in Unix (system call)

只愿长相守 提交于 2019-12-17 03:18:25
问题 I am not able to find a solution to my problem online. I would like to call a function in Unix, pass in the path of a directory, and know if it exists. opendir() returns an error if a directory does not exist, but my goal is not to actually open, check the error, close it if no error, but rather just check if a file is a directory or not. Is there any convenient way to do that please? 回答1: There are two relevant functions on POSIX systems: stat() and lstat(). These are used to find out