{"id":17954347,"url":"https://github.com/txthinking/denolib","last_synced_at":"2025-12-11T21:14:57.421Z","repository":{"id":39782275,"uuid":"265835691","full_name":"txthinking/denolib","owner":"txthinking","description":"A Deno library to keep everything small.","archived":false,"fork":false,"pushed_at":"2023-03-16T12:40:48.000Z","size":120,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-17T22:07:42.840Z","etag":null,"topics":["crypto","database","database-migrations","deno","denojs","httpserver","kiss","library","migration","redis"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/txthinking.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":"txthinking","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2020-05-21T11:52:31.000Z","updated_at":"2024-03-11T01:02:07.000Z","dependencies_parsed_at":"2023-01-22T09:45:52.129Z","dependency_job_id":null,"html_url":"https://github.com/txthinking/denolib","commit_stats":null,"previous_names":["txthinking/sf"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/txthinking%2Fdenolib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/txthinking%2Fdenolib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/txthinking%2Fdenolib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/txthinking%2Fdenolib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/txthinking","download_url":"https://codeload.github.com/txthinking/denolib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245377921,"owners_count":20605374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crypto","database","database-migrations","deno","denojs","httpserver","kiss","library","migration","redis"],"created_at":"2024-10-29T10:14:05.590Z","updated_at":"2025-12-11T21:14:52.371Z","avatar_url":"https://github.com/txthinking.png","language":"JavaScript","readme":"\n# Denolib\n\n*A **Deno** library to keep everything small.*\n\n\u003cbr\u003e\n\n## HTTP Server\n\n\u003cbr\u003e\n\n```javascript\nimport server from 'https://raw.githubusercontent.com/txthinking/denolib/master/httpserver.js';\n\nserver.path('/hello',async (request) =\u003e\n    new Response('Hello World',{ status : 200 }));\n\nserver.run({ port : 2020 });\n```\n\n\u003cbr\u003e\n\n### Static\n\n```javascript\nhttpserver.staticdir = '/path/to/static';\n```\n\n### Static + **[DenoBundle]**\n\n```javascript\nimport readFileSync from './bundle.js';\n\nhttpserver.readfile = (path) =\u003e \n    readFileSync('static' + path);\n```\n\n\u003cbr\u003e\n\n### SPA\n\n```javascript\nhttpserver.spa = true;\n```\n\n\u003cbr\u003e\n\n### CORS\n\n```javascript\nhttpserver.cors = '*';\n```\n\n\u003cbr\u003e\n\n### 404\n\n```javascript\nhttpserver.default = (request) =\u003e {...}\n```\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n## Crypto\n\n```javascript\nimport crypto from 'https://raw.githubusercontent.com/txthinking/denolib/master/crypto.js';\n\n// Pass in a 32 length key\n\nconst kv = crypto('abcdefghijklmnopqrstuvwxyz012345');\n\nconst token = await kv.encrypt('uid',1);\n\nconst uid = await kv.decrypt('uid',token);\n```\n\n```javascript\n// Only allow token to be valid for 30 days\n\nconst uid = await kv.decrypt('uid',token,30 * 24 * 60 * 60);\n```\n\n\u003cbr\u003e\n\n---\n\n\u003cbr\u003e\n\n## MySQL\n\n\u003cbr\u003e\n\n### Connect\n\n```javascript\nimport mysql from 'https://raw.githubusercontent.com/txthinking/denolib/master/mysql.js';\n\nconst database = await mysql({\n    hostname : '127.0.0.1' ,\n    password : '111111' ,\n    username : 'root' ,\n    poolSize : 3 ,\n    port : 3306 ,\n    db : 'dbname'\n});\n```\n\n\u003cbr\u003e\n\n### Migrate\n\n```javascript\nimport migrate from 'https://raw.githubusercontent.com/txthinking/denolib/master/migrate.js';\n\nconst mg = await migrate(database);\n\n// Each unique id execute at most once\n\nawait mg('A unique id string', `\n    CREATE TABLE user (\n        id int(10) unsigned NOT NULL AUTO_INCREMENT,\n        email varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL default '',\n        PRIMARY KEY (id)\n    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci\n`);\n\nawait mg('Another unique id string','another sql');\n```\n\n\u003cbr\u003e\n\n### Curd\n\n\u003e if you want to use this four methods, set auto increment primary key: id, set not null and default value for each field\n\n```javascript\n// table name and row object, keys must match table fields or less\n\nconst row = await database.c('user',{ \n    email : 'hi@httpserver.com'\n});\n```\n\n```javascript\n// object keys must match table fields or less and must contain id\n\nconst row = await database.u('user',{ \n    email : 'hey@httpserver.com' ,\n    id : 1 \n});\n```\n\n```javascript\n// pass in id\n\nconst row = await database.r('user',1);\n```\n\n```javascript\n// pass in id\n\nawait database.d('user',1);\n```\n\n\u003cbr\u003e\n\n### SQL\n\n```javascript\nconst rows = await database.query(\n    'select * from user where id=?',[1]);\n\nawait database.execute(\n    'update user set email=? where id=?',\n    [ 'hi@httpserver.com' , 1 ]);\n```\n\n\u003cbr\u003e\n\n### Transaction\n\n```javascript\nconst request = await database.transaction(async (database) =\u003e {\n    \n    const request = await database.c('user',{\n        email : 'hey@httpserver.com'\n    });\n    \n    // throw new Error('rollback');\n    \n    await database.execute('update user set email=? where id=?',\n        [ 'hi@httpserver.com' , 1 ]);\n    \n    const rows = await database.query(\n        'select * from user where id=?',[1]);\n    \n    return rows;\n});\n```\n\n\u003cbr\u003e\n\n---\n\n\u003cbr\u003e\n\n## Redis\n\n\u003cbr\u003e\n\n### Connect\n\n```javascript\nimport redis from 'https://raw.githubusercontent.com/txthinking/denolib/master/redis.js';\n\nconst rds = await redis({\n    hostname : '127.0.0.1' , \n    port : 6379\n});\n```\n\n\u003cbr\u003e\n\n### command\n\n```javascript\nconst request = await rds.exec( 'set' , 'hi' , 'httpserver' );\n```\n\n```javascript\nconst request = await rds.exec( 'get' , 'hi' );\n```\n\n### Pipeline\n\n```javascript\nawait rds.pipeline((rds) =\u003e {\n    rds.exec( 'set' , 'hi' , 'httpserver' );\n    rds.exec( 'set' , 'hey' , 'httpserver' );\n});\n```\n\n### Transaction\n\n\u003e Guarantee atomicity\n\n```javascript\nawait rds.transaction((rds) =\u003e {\n    rds.exec( 'set' , 'hi' , 'httpserver1' );\n    rds.exec( 'set' , 'hey' , 'httpserver2' );\n});\n```\n\n### Subscribe\n\n```javascript\nconst channel = await rds.subscribe('channel');\n\nfor await (const event of channel.receive())\n    console.log(event);\n```\n\n\u003cbr\u003e\n\n\n\u003c!-----------------------------------------------------------------------------\u003e\n\n[denobundle]: https://github.com/txthinking/denobundle\n","funding_links":["https://github.com/sponsors/txthinking"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftxthinking%2Fdenolib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftxthinking%2Fdenolib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftxthinking%2Fdenolib/lists"}