or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

attachment-operations.mdchanges-feed.mddatabase-operations.mddocument-operations.mdhttp-utilities.mdindex.md

database-operations.mddocs/

0

# Database Operations

1

2

Core database management functionality for establishing connections, retrieving database information, and managing database lifecycle operations.

3

4

## Capabilities

5

6

### HttpPouch Constructor

7

8

Creates a new HTTP adapter instance connected to a remote database.

9

10

```javascript { .api }

11

/**

12

* Creates an HTTP adapter instance for connecting to remote CouchDB

13

* @param opts - Configuration options for the database connection

14

* @param callback - Callback function called when setup is complete

15

*/

16

function HttpPouch(opts, callback);

17

```

18

19

**Usage Examples:**

20

21

```javascript

22

// Basic connection

23

const db = new PouchDB('http://localhost:5984/mydb');

24

25

// With authentication

26

const db = new PouchDB('http://localhost:5984/mydb', {

27

auth: {

28

username: 'admin',

29

password: 'secret'

30

}

31

});

32

33

// With custom headers

34

const db = new PouchDB('http://localhost:5984/mydb', {

35

headers: {

36

'Custom-Header': 'value'

37

}

38

});

39

```

40

41

### Database Information

42

43

Retrieves comprehensive information about the connected database.

44

45

```javascript { .api }

46

/**

47

* Get database information including document counts and metadata

48

* @param callback - Callback function receiving database info

49

*/

50

api._info(callback): void;

51

```

52

53

**Usage Examples:**

54

55

```javascript

56

db.info((err, info) => {

57

if (err) {

58

console.error('Error getting database info:', err);

59

return;

60

}

61

62

console.log('Database name:', info.db_name);

63

console.log('Document count:', info.doc_count);

64

console.log('Update sequence:', info.update_seq);

65

console.log('Host URL:', info.host);

66

});

67

```

68

69

### Database ID Generation

70

71

Generates a unique identifier for the database connection.

72

73

```javascript { .api }

74

/**

75

* Generate unique database ID based on server UUID and database name

76

* @param callback - Callback function receiving the database ID

77

*/

78

api.id(callback): void;

79

```

80

81

**Usage Examples:**

82

83

```javascript

84

db.id((err, id) => {

85

if (err) {

86

console.error('Error getting database ID:', err);

87

return;

88

}

89

90

console.log('Database ID:', id);

91

});

92

```

93

94

### Database Compaction

95

96

Triggers database compaction to reduce storage size and improve performance.

97

98

```javascript { .api }

99

/**

100

* Trigger database compaction on the remote server

101

* @param opts - Compaction options including polling interval

102

* @param callback - Callback function called when compaction completes

103

*/

104

api.compact(opts, callback): void;

105

```

106

107

**Usage Examples:**

108

109

```javascript

110

// Basic compaction

111

db.compact((err, result) => {

112

if (err) {

113

console.error('Compaction failed:', err);

114

return;

115

}

116

117

console.log('Compaction completed:', result.ok);

118

});

119

120

// With custom polling interval

121

db.compact({ interval: 500 }, (err, result) => {

122

if (err) {

123

console.error('Compaction failed:', err);

124

return;

125

}

126

127

console.log('Compaction completed:', result.ok);

128

});

129

```

130

131

### Database Destruction

132

133

Permanently deletes the remote database and all its contents.

134

135

```javascript { .api }

136

/**

137

* Delete the remote database permanently

138

* @param options - Destruction options (currently unused)

139

* @param callback - Callback function called when deletion completes

140

*/

141

api._destroy(options, callback): void;

142

```

143

144

**Usage Examples:**

145

146

```javascript

147

db.destroy((err, result) => {

148

if (err) {

149

console.error('Database destruction failed:', err);

150

return;

151

}

152

153

console.log('Database destroyed:', result.ok);

154

});

155

```

156

157

### Connection Closure

158

159

Closes the database connection and cleans up resources.

160

161

```javascript { .api }

162

/**

163

* Close the database connection

164

* @param callback - Callback function called when connection is closed

165

*/

166

api._close(callback): void;

167

```

168

169

**Usage Examples:**

170

171

```javascript

172

db.close((err) => {

173

if (err) {

174

console.error('Error closing database:', err);

175

return;

176

}

177

178

console.log('Database connection closed');

179

});

180

```

181

182

## Types

183

184

```javascript { .api }

185

// Constructor options

186

interface HttpPouchOptions {

187

name: string;

188

auth?: AuthOptions;

189

headers?: { [key: string]: string };

190

fetch?: Function;

191

skip_setup?: boolean;

192

}

193

194

interface AuthOptions {

195

username: string;

196

password: string;

197

}

198

199

// Database info response

200

interface DatabaseInfo {

201

db_name: string;

202

doc_count: number;

203

doc_del_count: number;

204

update_seq: string | number;

205

purge_seq: string | number;

206

compact_running: boolean;

207

disk_size: number;

208

data_size: number;

209

instance_start_time: string;

210

disk_format_version: number;

211

committed_update_seq: string | number;

212

host: string;

213

}

214

215

// Compact options

216

interface CompactOptions {

217

interval?: number;

218

}

219

220

// Standard result format

221

interface StandardResult {

222

ok: boolean;

223

}

224

```