本文整理汇总了TypeScript中pg.Client.connect方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Client.connect方法的具体用法?TypeScript Client.connect怎么用?TypeScript Client.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pg.Client
的用法示例。
在下文中一共展示了Client.connect方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: start
public async start() {
this.counter = 0;
this.client = new Client(this.config);
await this.client.connect();
console.log("Database started");
}
示例2: Client
.then((location) => {
let client = new Client({
host: location.hostname,
port: location.port || 5432,
database: database,
user: user,
password: password,
parseInputDatesAsUTC: true // not in the type
} as any);
client.on('drain', client.end.bind(client)); // disconnect client when all queries are finished
client.connect();
//query is executed once connection is established and PostgreSQL server is ready for a query
let q = client.query(new (Query as any)(query) as any);
// ToDo: use node-pg-cursor or node-pg-query-stream here instead
q.on('row', function(row: any) {
stream.push(row);
});
q.on('error', function(err: any) {
stream.emit('error', err); // Pass on any errors
});
q.on('end', function() {
stream.push(null); // pushing null, indicating EOF
});
})
示例3: reject
await new Promise<void>((resolve, reject) => connection.connect((err) => {
if (err) {
reject(err);
} else {
resolve();
}
}));
示例4: Client
export async function query<T>(config: ConnectionConfig, queryText: string, values: any[] = []) {
const client = new Client(config)
await client.connect()
const result = await client.query(queryText, values)
await client.end()
return result as QueryResult<T>
}
示例5: async
const run = async () => {
const dbCreate = new Client({})
await dbCreate.connect()
try {
await dbCreate.query('drop database gandalf_test')
} catch (err) {
console.log('drop err', err.message)
}
await dbCreate.query('create database gandalf_test')
await dbCreate.end()
await client.connect()
await createPersons()
.then(createCompanies)
.then(createProducts)
.then(createOrders)
.then(createViews)
await client.end()
}
示例6: places
return new Promise<string>((resolve, reject) => {
const client = new pg.Client(conString)
client.connect()
client.query('INSERT INTO places (description, location, place_id) VALUES ($1, $2, $3)',
[place.description, '('+place.location.lat+','+place.location.lng+')', place.id], ( error, result) => {
if(error) reject(error)
if(result) resolve('OK')
client.end()
})
})
示例7: resolve
return new Promise<boolean>((resolve, reject) => {
const client = new pg.Client(conString)
client.connect()
client.query('SELECT place_id FROM places WHERE description = \'' + input + '\' LIMIT 1', ( error, result) => {
if(error) reject(error)
if(result.rowCount) resolve(true)
else resolve(false)
client.end()
})
})
示例8: testSchema
async function testSchema(sql: string) {
const client = new Client(connectionDetails)
await client.connect()
await client.query('DROP SCHEMA IF EXISTS DatabaseIntrospector cascade;')
await client.query('CREATE SCHEMA DatabaseIntrospector;')
await client.query('SET search_path TO DatabaseIntrospector;')
await client.query(sql)
expect(await introspect()).toMatchSnapshot()
await client.end()
}