Skip to content

Commit dadccff

Browse files
Merge pull request #672 from MasoniteFramework/feature/671
added missing float
2 parents 4104555 + 000b1e2 commit dadccff

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

src/masoniteorm/schema/Blueprint.py

+22
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,28 @@ def decimal(self, column, length=17, precision=6, nullable=False):
376376
)
377377
return self
378378

379+
def float(self, column, length=19, precision=4, nullable=False):
380+
"""Sets a column to be the float representation for the table.
381+
382+
Arguments:
383+
column {string} -- The name of the column.
384+
385+
Keyword Arguments:
386+
length {int} -- The total length of the float number (default: {17})
387+
precision {int} -- The number of places that should be used for floating numbers. (default: {6})
388+
nullable {bool} -- Whether the column is nullable (default: {False})
389+
390+
Returns:
391+
self
392+
"""
393+
self._last_column = self.table.add_column(
394+
column,
395+
"float",
396+
length="{length}, {precision}".format(length=length, precision=precision),
397+
nullable=nullable,
398+
)
399+
return self
400+
379401
def double(self, column, nullable=False):
380402
"""Sets a column to be the the double representation for the table
381403

tests/mssql/schema/test_mssql_schema_builder.py

+10
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ def test_can_add_columns_with_constaint(self):
4343
],
4444
)
4545

46+
def test_can_have_float_type(self):
47+
with self.schema.create("users") as blueprint:
48+
blueprint.float("amount")
49+
50+
self.assertEqual(
51+
blueprint.to_sql(),
52+
["""CREATE TABLE [users] ("""
53+
"""[amount] FLOAT(19, 4) NOT NULL)"""],
54+
)
55+
4656
def test_can_have_unsigned_columns(self):
4757
with self.schema.create("users") as blueprint:
4858
blueprint.integer("profile_id").unsigned()

tests/mysql/schema/test_mysql_schema_builder.py

+9
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,15 @@ def test_can_have_default_blank_string(self):
281281
["CREATE TABLE `users` (" "`profile_id` VARCHAR(255) NOT NULL DEFAULT '')"],
282282
)
283283

284+
def test_can_have_float_type(self):
285+
with self.schema.create("users") as blueprint:
286+
blueprint.float("amount")
287+
288+
self.assertEqual(
289+
blueprint.to_sql(),
290+
["CREATE TABLE `users` (" "`amount` FLOAT(19, 4) NOT NULL)"],
291+
)
292+
284293
def test_has_table(self):
285294
schema_sql = self.schema.has_table("users")
286295

tests/postgres/schema/test_postgres_schema_builder.py

+10
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,16 @@ def test_can_add_binary_column(self):
319319
['CREATE TABLE "binary_storing" ("filecontent" BYTEA NOT NULL)'],
320320
)
321321

322+
def test_can_have_float_type(self):
323+
with self.schema.create("users") as blueprint:
324+
blueprint.float("amount")
325+
326+
self.assertEqual(
327+
blueprint.to_sql(),
328+
["""CREATE TABLE "users" ("""
329+
"""\"amount" FLOAT(19, 4) NOT NULL)"""],
330+
)
331+
322332
def test_can_enable_foreign_keys(self):
323333
sql = self.schema.enable_foreign_key_constraints()
324334

tests/sqlite/schema/test_sqlite_schema_builder.py

+10
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ def test_can_add_columns_with_constraint(self):
5757
],
5858
)
5959

60+
def test_can_have_float_type(self):
61+
with self.schema.create("users") as blueprint:
62+
blueprint.float("amount")
63+
64+
self.assertEqual(
65+
blueprint.to_sql(),
66+
["""CREATE TABLE "users" ("""
67+
"""\"amount" FLOAT(19, 4) NOT NULL)"""],
68+
)
69+
6070
def test_can_add_columns_with_foreign_key_constraint(self):
6171
with self.schema.create("users") as blueprint:
6272
blueprint.string("name").unique()

0 commit comments

Comments
 (0)