MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / createTable

Function createTable

run/idp-sql/cloud-sql.js:132–149  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

130 * Create "votes" table in the Cloud SQL database
131 */
132const createTable = async () => {
133 if (!knex) knex = await connect();
134 const exists = await knex.schema.hasTable(TABLE);
135 if (!exists) {
136 try {
137 await knex.schema.createTable(TABLE, table => {
138 table.bigIncrements('vote_id').notNull();
139 table.timestamp('time_cast').notNull();
140 table.specificType('candidate', 'CHAR(6) NOT NULL');
141 table.specificType('uid', 'VARCHAR(128) NOT NULL');
142 });
143 logger.info(`Successfully created ${TABLE} table.`);
144 } catch (err) {
145 const message = `Failed to create ${TABLE} table: ${err}`;
146 logger.error(message);
147 }
148 }
149};
150
151const closeConnection = () => {
152 if (!knex) knex.destroy();

Callers 1

mainFunction · 0.85

Calls 1

connectFunction · 0.70

Tested by

no test coverage detected