aboutsummaryrefslogtreecommitdiff
path: root/src/database.ts
diff options
context:
space:
mode:
authorShinigami <[email protected]>2022-01-14 17:13:49 +0100
committerDamien Retzinger <[email protected]>2022-01-14 18:37:49 -0500
commit4d4653e6cdfd551b5d6d7a939c85f4232391a235 (patch)
tree19ec42733dd3cb7b6fcd9f34e720fb055094496d /src/database.ts
parent3c3e567f4d9d901770a76bf30068a6742a00d882 (diff)
downloadfaker-4d4653e6cdfd551b5d6d7a939c85f4232391a235.tar.xz
faker-4d4653e6cdfd551b5d6d7a939c85f4232391a235.zip
feat: migrate database (#89)
Diffstat (limited to 'src/database.ts')
-rw-r--r--src/database.ts77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/database.ts b/src/database.ts
new file mode 100644
index 00000000..c0513bbc
--- /dev/null
+++ b/src/database.ts
@@ -0,0 +1,77 @@
+import type { Faker } from '.';
+
+export class Database {
+ constructor(private readonly faker: Faker) {
+ // Bind `this` so namespaced is working correctly
+ for (const name of Object.getOwnPropertyNames(Database.prototype)) {
+ if (name === 'constructor' || typeof this[name] !== 'function') {
+ continue;
+ }
+ this[name] = this[name].bind(this);
+ }
+
+ // TODO @Shinigami92 2022-01-11: We should find a better strategy as assigning this property to a function
+ // @ts-expect-error
+ this.column.schema = {
+ description: 'Generates a column name.',
+ sampleResults: ['id', 'title', 'createdAt'],
+ };
+ // @ts-expect-error
+ this.type.schema = {
+ description: 'Generates a column type.',
+ sampleResults: ['byte', 'int', 'varchar', 'timestamp'],
+ };
+ // @ts-expect-error
+ this.collation.schema = {
+ description: 'Generates a collation.',
+ sampleResults: ['utf8_unicode_ci', 'utf8_bin'],
+ };
+ // @ts-expect-error
+ this.engine.schema = {
+ description: 'Generates a storage engine.',
+ sampleResults: ['MyISAM', 'InnoDB'],
+ };
+ }
+
+ /**
+ * column
+ *
+ * @method faker.database.column
+ */
+ column() {
+ return this.faker.random.arrayElement(
+ this.faker.definitions.database.column
+ );
+ }
+
+ /**
+ * type
+ *
+ * @method faker.database.type
+ */
+ type() {
+ return this.faker.random.arrayElement(this.faker.definitions.database.type);
+ }
+
+ /**
+ * collation
+ *
+ * @method faker.database.collation
+ */
+ collation() {
+ return this.faker.random.arrayElement(
+ this.faker.definitions.database.collation
+ );
+ }
+
+ /**
+ * engine
+ *
+ * @method faker.database.engine
+ */
+ engine() {
+ return this.faker.random.arrayElement(
+ this.faker.definitions.database.engine
+ );
+ }
+}