{"id":16369687,"url":"https://github.com/dcsunset/thssdb","last_synced_at":"2025-08-23T12:37:00.039Z","repository":{"id":98895757,"uuid":"259046890","full_name":"DCsunset/ThssDB","owner":"DCsunset","description":"A SQL database written in Java from scratch for a database course","archived":false,"fork":false,"pushed_at":"2023-09-13T03:34:57.000Z","size":467,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T03:11:26.136Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DCsunset.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-26T14:10:36.000Z","updated_at":"2025-04-06T06:08:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"d5d1cab3-364e-4a88-99a2-39c1e8af42a2","html_url":"https://github.com/DCsunset/ThssDB","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/DCsunset/ThssDB","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DCsunset%2FThssDB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DCsunset%2FThssDB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DCsunset%2FThssDB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DCsunset%2FThssDB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DCsunset","download_url":"https://codeload.github.com/DCsunset/ThssDB/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DCsunset%2FThssDB/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271747026,"owners_count":24813605,"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","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-11T02:56:02.334Z","updated_at":"2025-08-23T12:36:59.980Z","avatar_url":"https://github.com/DCsunset.png","language":"Java","readme":"# ThssDB\n\nA SQL database written in Java from scratch for a database course.\n\n## Usage\n\nRun `maven clean install` first to install dependencies.\n\nThe following java program can be run directly:\n\n* Server: `server/ThssDB.java`\n* Interactive client: `client/OurClient.java`\n* Client test: `client/Client.java`\n\n## Manual\n\nAfter starting the server and the client,\na command prompt will be available at the client.\n\n### Authentication\n\nAfter running the client, login is required before using the datbase.\nYou can use the following commands for authentication:\n\n```sql\n-- login\nconnect \u003cusername\u003e \u003cpassword\u003e\n-- logout\ndisconnect\n```\n\nA default user is created with the username `username` and password `password`.\n\n\n### User Management\n\nAfter login, you can manage the user using the following commands:\n\n```sql\n-- create a user\ncreate user \u003cusername\u003e identified by \u003cpassword\u003e;\n-- change user password\nalter user \u003cusername\u003e set password \u003cpassword\u003e;\n-- delete a user\ndrop user \u003cusername\u003e;\n```\n\n### SQL Queries\n\n#### Database Management\n\n```sql\n-- create a database\n-- return error if the database already exists\nCREATE DATABASE dbName;\n\n-- switch current datbase\n-- return error if the database doesn't exist\nUSE dbName;\n\n-- drop database\n-- return error if the database doesn't exist\nDROP DATABASE dbName;\n```\n\n\n#### Table Creation\n\nTo create a table in the current database:\n\n\n```sql\n-- create a table in current database\n-- return error if the table already exists\nCREATE TABLE tableName(attrName1 Type1, attrName2 Type2, ..., attrNameN TypeN NOT NULL, PRIMARY KEY(attrName1));\n```\n\n\nThis database supports 5 types: `String(n)`, `Int`, `Long`, `Float`, `Double`.\nYou can use one of the above types for each attribute in the table.\n\nNote: `primary key(attr)` must be used on an existing attribute,\nand `not null` can be appended after any attribute definition.\n\n\n#### Table Management\n\n```sql\n-- show metadata of the table\n-- return error if the table doesn't exist\nSHOW TABLE tableName;\n-- drop a table\n-- return error if the table doesn't exist\nDROP TABLE tableName;\n```\n\n#### Insert\n\n```sql\nINSERT INTO tableName(attrName1, attrName2,…, attrNameN) VALUES (attrValue1, attrValue2,…, attrValueN);\n```\n\nThe attribute list after the table is optional.\nif it's not specified, you need to provide values for all attributes.\nOtherwise, you can just provide valus corresponding to the specified attribute names (other attributes will be `null`).\nThe `not null` constraint will be checked if any attribute has it defined.\n\n#### Update\n\n```sql\nUPDATE tableName SET attrName = attrValue WHERE \u003ccondition\u003e;\n```\n\nThe condition supports multiple expressions joined by `\u0026\u0026` or `||` operators,\nattribute names and constant expressions are supported in the condition clause.\nConstant expression\n\nFor example：\n\n```sql\nupdate student set tot_cred = 25*5 where tot_cred \u003e= 25*(6-1) \u0026\u0026 tot_cred \u003c= 127;\n```\n\n#### Select\n\nFor a single table:\n\n```sql\nSELECT attrName1, attrName2, … attrNameN FROM tableName [ WHERE  \u003ccondition\u003e ]\n```\n\nFor multiple tables\n\n```sql\nSELECT tableName1.AttrName1, tableName1.AttrName2…, tableName2.AttrName1, tableName2.AttrName2,… FROM tableName1 JOIN tableName2  ON  tableName1.attrName1 = tableName2.attrName2 [ WHERE \u003ccondition\u003e ]\n```\n\nThe where clause is optional in the above queries.\nIf only one `*` is used for the attribute name,\nit will represent all the attributes.\n\nWhen used with multiple tables,\nthe tableName can't be ommited.\n\nExmaple queries:\n\n```sql\ncreate table grade(id String(10), score Int);\ninsert into grade values('1', 80);\ninsert into grade values('2', 90);\ninsert into grade values('3', 99);\ninsert into grade values('4', 100);\ncreate table person(id String(10), name String(10));\ninsert into person values('1', 'A');\ninsert into person values('2', 'B');\ninsert into person values('3', 'C');\ninsert into person values('4', 'D');\ncreate table info(name String(10), birthday String(20));\ninsert into info values('A', '2000-1-1');\ninsert into info values('B', '2000-1-2');\ninsert into info values('C', '2000-1-3');\ninsert into info values('D', '2000-1-4');\nselect * from person join info join grade on grade.id = person.id \u0026\u0026 person.name = info.name;\n```\n\n\n### Transactions \u0026 Checkpoints\n\nThe following commands are supported:\n\n```sql\n-- begin a transaction\nbegin transaction;\n-- commit the current transaction\ncommit;\n-- roll back current transaction\nrollback;\n-- set checkpoint\ncheckpoint;\n```\n\nWhen a client begins a transaction,\nlocks will be required for involved tables.\nOther clients must wait for the transaction to finish\nbefore operating on the same table.\n\n\nThe `checkpoint` command will cause the server to write checkpoint to the log and persist the data.\nWhen recovering the data, it can start from the last checkpoing directly in the log,\nwhich will be more efficient compared to replaying all the logs.\n\nIn the mean time, `checkpoint` command will be periodically executed in another thread as well\nto improve the efficiency for crash recovery.\n\n\n## Copyright Notice\n\nAll rights reserved.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcsunset%2Fthssdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdcsunset%2Fthssdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdcsunset%2Fthssdb/lists"}